[thread] boost::shared_mutex vs. pthread_rwlock_unlock

I am replacing a pthread threading implementation with a boost threads implementation so I can use the code on Windows. There is a ReadWriteMutex class that has the following declaration: class ReadWriteMutex { public: ReadWriteMutex(); virtual ~ReadWriteMutex() {} // these get the lock and block until it is done successfully virtual void acquireRead() const; virtual void acquireWrite() const; // these attempt to get the lock, returning false immediately if they fail virtual bool attemptRead() const; virtual bool attemptWrite() const; // this releases both read and write locks virtual void release() const; private: class impl; boost::shared_ptr<impl> impl_; }; Note the release() method that works for a thread that holds either the read or write lock. My implementation uses boost::shared_mutex. acquireRead calls lock_shared(), acquireWrite calls lock(), attemptRead calls try_lock_shared(), attemptWrite calls try_lock, and release calls ??????? AFAICT there is no equivalent to the pthread_rwlock_unlock() call that the original version of release() called. Am I missing something? Thanks, Rush

Rush Manbert <rush@manbert.com> writes:
I am replacing a pthread threading implementation with a boost threads implementation so I can use the code on Windows.
class ReadWriteMutex { public: ReadWriteMutex(); virtual ~ReadWriteMutex() {}
// these get the lock and block until it is done successfully virtual void acquireRead() const; virtual void acquireWrite() const;
// these attempt to get the lock, returning false immediately if they fail virtual bool attemptRead() const; virtual bool attemptWrite() const;
// this releases both read and write locks virtual void release() const;
Note the release() method that works for a thread that holds either the read or write lock.
AFAICT there is no equivalent to the pthread_rwlock_unlock() call that the original version of release() called.
Am I missing something?
No, this is correct --- you must explicitly call unlock() or unlock_shared() depending on what sort of lock you have. Anthony -- Author of C++ Concurrency in Action | http://www.manning.com/williams just::thread C++0x thread library | http://www.stdthread.co.uk Just Software Solutions Ltd | http://www.justsoftwaresolutions.co.uk 15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK. Company No. 5478976
participants (2)
-
Anthony Williams
-
Rush Manbert