Boost logo

Threads-Devel :

From: Anthony Williams (anthony_at_[hidden])
Date: 2007-04-12 08:06:13


Russell Kliese <russell_at_[hidden]> writes:

> I've been trying to come up with a timed read/write lock for Linux to
> replace the implementation that was pulled from Boost. After looking
> over some of the messages is the mailing list, I decided to investigate
> wrapping up pthreads.

Did you not get the new version I posted? I've attached it again in case it
went astray.

> __rw_readers has to be zero, therefore it looks like the read lock must
> be released before obtaining a write lock (when a write lock is
> obtained, this value is incremented). This seems bad to me as it makes
> it tricky to handle upgrading and downgrading locks.
>
> Am I missing something here?

Yes. POSIX does not allow upgrading and downgrading --- a read lock is always
a read lock, and a write lock is always a write lock. The latest POSIX spec
says about pthread_rwlock_rdlock:

    "The calling thread may deadlock if at the time the call is made it holds
    a write lock."

and about pthread_rwlock_wrlock:

    "The calling thread may deadlock if at the time the call is made it holds
    the read-write lock (whether a read or write lock)."

Anthony

-- 
Anthony Williams
Just Software Solutions Ltd - http://www.justsoftwaresolutions.co.uk
Registered in England, Company Number 5478976.
Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL



Threads-Devel list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk