[Boost-bugs] [Boost C++ Libraries] #1905: shared_mutex::timed_lock can leave mutex thinking there's a waiting writer

Subject: [Boost-bugs] [Boost C++ Libraries] #1905: shared_mutex::timed_lock can leave mutex thinking there's a waiting writer
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2008-05-08 15:18:16


#1905: shared_mutex::timed_lock can leave mutex thinking there's a waiting writer
--------------------------+-------------------------------------------------
 Reporter: anthonyw | Owner: anthonyw
     Type: Bugs | Status: new
Milestone: Boost 1.36.0 | Component: thread
  Version: Boost 1.35.0 | Severity: Problem
 Keywords: |
--------------------------+-------------------------------------------------
 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;
 }

 }}}

--
Ticket URL: <http://svn.boost.org/trac/boost/ticket/1905>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.


This archive was generated by hypermail 2.1.7 : 2017-02-16 18:49:57 UTC