Fw: [patch] Make std::tr1::shared_ptr thread-safe.

Peter Dimov pdimov@mmltd.net
Thu Mar 31 19:09:00 GMT 2005


Alexander Terekhov wrote:
> "Peter Dimov" <pdimov@mmltd.net> on 03/30/2005 11:33:56 PM:
> [...]
>> 3. Making __exchange_and_add offer the following memory
>> synchronization guarantees:
>>
>> - acquire memory semantics when the result is not zero;
>> - release memory semantics when the result is zero
>
> release memory semantics when the result is not zero;
> acquire memory semantics when the result is zero

Umm, of course.

> And "result" means new value of count stored by __exchange_and_add(),
> not return value (its old value). BTW, I had a typo in my previous
> message when I wrote "result > 1".

[...]

> void weak_release() throw() {
>   if (!self_count_.decrement(msync::acq, count::may_not_store_min))

In an expanded form:

- no memory synchronization when the result is not zero (old value > 1)
- acquire memory semantics when the old value is 1 (may skip the final store 
of 0)

>     destruct();
> }
>
> void release() throw() {
>   if (!use_count_.decrement()) { // "full" release-acquire protocol

As above:

- release memory semantics when the result is not zero;
- acquire memory semantics when the result is zero

>     dispose();
>     if (!self_count_.decrement(msync::rel, count::may_not_store_min))

- release memory semantics when result is not zero (old value > 1)
- no-op when the old value is 1 (no memory synchronization, may skip the 
final store of 0)

>       destruct();
>   }
> }

Right?



More information about the Libstdc++ mailing list