Opened 14 years ago
Closed 14 years ago
#1905 closed Bugs (fixed)
shared_mutex::timed_lock can leave mutex thinking there's a waiting writer
Reported by: | Anthony Williams | Owned by: | Anthony Williams |
---|---|---|---|
Milestone: | Boost 1.36.0 | Component: | thread |
Version: | Boost 1.35.0 | Severity: | Problem |
Keywords: | Cc: |
Description
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; }
Note:
See TracTickets
for help on using tickets.
Fixed on trunk, revision 45242