Boost logo

Boost Users :

From: Mark Westcott (mark-boost_at_[hidden])
Date: 2008-05-08 10:49:15


Hi all,

I'm experiencing a deadlock in the following code. After an timed out
call to boost::shared_mutex::timed_lock(),
boost::mutex::state.exclusive_waiting_blocked equals 1, which makes
further attempts to shared_lock the mutex block indefinitely.

Is this a bug, or are my expectations wrong?

Thanks,

Mark

#include <boost/thread/thread.hpp>
#include <boost/thread/shared_mutex.hpp>

#include <iostream>

using namespace std;

boost::shared_mutex mutex;

void thread()
{
   boost::system_time timeout=boost::get_system_time() +
   boost::posix_time::milliseconds(500);
   if (mutex.timed_lock(timeout)) {
       mutex.unlock();
   } else {
       cout << "thread1: failed to obtain exclusive lock" << endl;
       // now mutex.state.exclusive_waiting_blocked == 1;

       cout << "thread1: attempting to obtain exclusive lock" << endl;

       mutex.lock_shared();
       //never get to here
       cout << "thread2: obtained shared lock" << endl;
       mutex.unlock_shared();
   }
}

int main(int argc, char* argv[])
{
 mutex.lock_shared();

 boost::thread my_thread(&thread);
 my_thread.join();

 mutex.unlock_shared();
 return 0;
}


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net