[cpp-threads] Failed compare-and-swap

Boehm, Hans hans.boehm at hp.com
Fri Aug 3 01:07:08 BST 2007


I'm confused.  I thought we had success and failure orders, not read and
write orders.  If you go with read/write, you can't drop the acquire
constraint on failure, which is probably the most (only?) interesting
case in practice, right?

If we have success and failure orders, it seems more natural to me to
list the success case first, which also seems optimal in terms of
overloads.

Hans

> -----Original Message-----
> From: cpp-threads-bounces at decadentplace.org.uk 
> [mailto:cpp-threads-bounces at decadentplace.org.uk] On Behalf 
> Of Paul E. McKenney
> Sent: Thursday, August 02, 2007 4:55 PM
> To: C++ threads standardisation
> Subject: Re: [cpp-threads] Failed compare-and-swap
> 
> 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
> 
> --
> cpp-threads mailing list
> cpp-threads at decadentplace.org.uk
> http://www.decadentplace.org.uk/cgi-bin/mailman/listinfo/cpp-threads
> 



More information about the cpp-threads mailing list