[cpp-threads] Failed compare-and-swap

Peter Dimov pdimov at mmltd.net
Wed Aug 1 22:04:11 BST 2007


Lawrence Crowl wrote:

> The current design returns a boolean and also modifies
> the reference parameter.
>
> I contend that for the spurious-fail CAS that we have, any
> reasonable code will need to re-read the value in the case
> of failure, and so separating the read from the CAS is
> ultimately pointless.

Another - possibly academic - argument in favor of this design is that it 
returns the exact storage bits of the location, whereas an atomic load 
returns by value and may not preserve any non-value (padding) bits.

This usually doesn't matter except for CAS, since it does a bitwise 
comparison of the storage bits and not a value comparison, so preserving the 
padding bits may be important if the CAS is to eventually succeed. 




More information about the cpp-threads mailing list