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
#include
#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;
}