[cpp-threads] Failed compare-and-swap

Peter Dimov pdimov at mmltd.net
Tue Jul 31 20:19:56 BST 2007


Boehm, Hans wrote:

...

>> The point well illustrated by these examples is that if CAS
>> returns the old value (rather than a bool) it can be used to
>> perform an atomic load. If we allow that, then it should have
>> the same default acquire semantics as a load (unless
>> overridden in the weak/relaxed atomics of course).
>>
>> Lawrence and everyone, what do you think? Now that I see
>> this, it seems obvious in retrospect, and this question must
>> have come up before with CAS semantics. What do other systems do?

> I completely agree with this.  If a CAS can be used to read the old
> value (which it can, arguably if it only has a boolean result), and it
> has at least acquire semantics, then it should still have acquire
> semantics even if it fails and the write doesn't take place.
> The read still succeeds.

I don't agree, not unless there is reasonably solid evidence that more than 
50% of the code needs the extra barrier. Paying for something that is not 
needed is not what C++ is about.

...

> We clearly need the acquire property for at least seq_cst, since we
> don't otherwise get sequential consistency for race-free programs.

No, we need sequential consistency for seq_cst, not acquire. The need for 
acquire in the acq_rel case does not necessarily follow. 




More information about the cpp-threads mailing list