[cpp-threads] Failed compare-and-swap

Paul E. McKenney paulmck at linux.vnet.ibm.com
Fri Aug 3 00:54:35 BST 2007


On Thu, Aug 02, 2007 at 03:36:35PM -0700, Lawrence Crowl wrote:
> On 8/2/07, Peter Dimov <pdimov at mmltd.net> wrote:
> > Lawrence Crowl wrote:
> > > On 8/2/07, Boehm, Hans <hans.boehm at hp.com> wrote:
> >
> > >> Does it make sense to use an additional overload instead of a default
> > >> value, so that failure_order can effectively default to
> > >> success_order? I think that's clearly the correct default for
> > >>
> > >> seq_cst, relaxed, and release
> > >>
> > >> since release becomes vacuous in the failure case, since there is no
> > >> store.
> > >
> > > That could work, but we'd need three overloads.
> >
> > Two are enough for that default.
> >
> > compare_swap( int& e, int d, memory_order w, memory_order r );
> >
> > compare_swap( int& e, int d, memory_order w = memory_order_seq_cst )
> > {
> >     compare_swap( e, d, w, w );
> > }
> 
> Ah, yes, if you switch the order of parameters.  Hans has already
> said he likes the switched order.  Any other opinions?

Given that the read happens before the write (in principle, anyway),
I believe that we would come to deeply regret putting the write-side
memory-order argument before the read-side memory-order argument.

An extra overload seems to me to be a small price to pay in this
case.

> > The first overload can be made to strip release from r.
> 
> I think that if the parameter is explicit, it should be exactly right.
> We currently require programmers to use the right form, and I'd
> like to leave it that way.

Since many programs are read much more frequently than they are written,
I agree with requiring the correct form.

							Thanx, Paul



More information about the cpp-threads mailing list