Boost logo

Threads-Devel :

Subject: Re: [Threads-devel] shared_mutex strategy
From: Anthony Williams (anthony_at_[hidden])
Date: 2010-05-19 04:43:19

On 19/05/10 09:35, Damien R wrote:
> Anthony Williams wrote:
>> If a reader gets the lock first, then more readers will be allowed to
>> get the lock until a waiting writer wakes and registers its intent.
> Yes, so in the worst case, only one reader will be able to read because
> when the last reader unlocks the mutex, it notifies all waiters. For eg:
> ----
> reader 0, 1, 2, 3 and writer 0 have the same priority
> reader 0, 1, 2, 3 and writer 0 are waiting
> last_reader notify all waiters
> reader 0 call lock_shared and increment the number of readers
> writer call lock(), so it change the state and wait until it is wake up
> reader 1, 2, 3 call lock_shared() and wait because the state was changed
> by the writer
> reader 0 release lock change state, notify all waiters
> ----
> Do you agree ?

Yes, that's a possible outcome. It does mean that the writer only has to
wait for the one reader before it gets another shot at acquiring the
lock, rather than waiting for all pending readers should a reader
acquire the lock.


Author of C++ Concurrency in Action
just::thread C++0x thread library   
Just Software Solutions Ltd
15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK. Company No. 5478976

Threads-Devel list run by bdawes at, david.abrahams at, gregod at, cpdaniel at, john at