[cpp-threads] N2800's C/C++MM and read-write locking

Alexander Terekhov alexander.terekhov at gmail.com
Thu Jan 8 17:17:58 GMT 2009


On Thu, Jan 8, 2009 at 3:01 PM, Peter Dimov <pdimov at mmltd.net> wrote:
>>> I also often tend to think of "rwlocks" as shared/exclusive locks.  If
>>> you really
>>> want to use weaker fences for readers, I think you would need to split
>>> them
>>> into two variantes: shared/exclusive and read/write.
>>
>> Care to elaborate?
>
> Something like:
>
> take shared lock
> try STM transaction in a lock-free manner
> unlock
>
> if failed
>    take write lock
>    use ordinary ops
>    unlock
>
> Here the lock is not used as a pure read lock since the transaction contains
> writes.

In SPARC RMO terms

http://www.decadentplace.org.uk/pipermail/cpp-threads/2008-December/001949.html

you mean:

take shared lock // trailing #LoadLoad|#LoadStore
try STM transaction in a lock-free manner
unlock // leading #StoreStore|#LoadStore

if failed
   take write lock // trailing #LoadLoad|#LoadStore
   use ordinary ops
   unlock // leading #StoreStore|#LoadStore

right?

Note that it can be done with read(-only) locking and additional more
fine-grained acquire/release fencing:

take read lock // trailing #LoadLoad
fence(acquire_minus_LoadLoad) // #LoadStore
try STM transaction in a lock-free manner
fence(release_minus_LoadStore) // #StoreStore
rd-unlock // leading LoadStore

if failed
   take write lock // trailing #LoadLoad|#LoadStore
   use ordinary ops
   unlock // leading #StoreStore|#LoadStore

correct?

regards,
alexander.



More information about the cpp-threads mailing list