[cpp-threads] Failed compare-and-swap

Lawrence Crowl Lawrence at Crowl.org
Wed Aug 1 21:58:04 BST 2007


On 8/1/07, Herb Sutter <hsutter at microsoft.com> wrote:
> It seems like there are two legitimate choices:
>
>   - CAS returns the old value, in which case a failed CAS
> should at least by default have acquire semantics because
> it's a read.
>
>   - CAS returns only a success/fail boolean, in which case
> a failed CAS need not have any ordering semantics.
>
> Does that make sense? It seems we can happily choose
> either, but the choice affects the return type.

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.

-- 
Lawrence Crowl



More information about the cpp-threads mailing list