[cpp-threads] Failed compare-and-swap

Lawrence Crowl Lawrence at Crowl.org
Thu Aug 2 00:21:38 BST 2007


On 8/1/07, Boehm, Hans <hans.boehm at hp.com> wrote:
> > 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.

And so for spurious failure, you would skip a slot?

The current CAS design also neatly covers the difference between
the hardware variants.

-- 
Lawrence Crowl



More information about the cpp-threads mailing list