[cpp-threads] Failed compare-and-swap
Boehm, Hans
hans.boehm at hp.com
Wed Aug 1 23:49:45 BST 2007
> From: Lawrence Crowl
>
> 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.
I think that's often, but not always true. I think I've written CAS
uses that check for a specific constant value, and are not preceded by a
read at all, e.g. if I need to store something in an empty slot, and it
really doesn't matter which of N slots I use.
Hans
More information about the cpp-threads
mailing list