[cpp-threads] Failed compare-and-swap
Paul E. McKenney
paulmck at linux.vnet.ibm.com
Fri Aug 3 01:46:32 BST 2007
On Fri, Aug 03, 2007 at 12:07:08AM -0000, Boehm, Hans wrote:
> 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?
Color me confused. :-/ I let the argument names of "r" and "w" distract
me from the true semantics of the arguments.
> 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.
I agree. The success-order argument should precede the failure-order
argument.
Thanx, Paul
> 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