Boost logo

Boost :

Subject: Re: [boost] [thread] boost::shared_mutex vs. pthread_rwlock_unlock
From: Anthony Williams (anthony.ajw_at_[hidden])
Date: 2009-05-05 06:36:55


Rush Manbert <rush_at_[hidden]> 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

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk