[cpp-threads] Failed compare-and-swap
Lawrence Crowl
Lawrence at Crowl.org
Thu Aug 2 23:15:07 BST 2007
On 8/2/07, Boehm, Hans <hans.boehm at hp.com> wrote:
> Lawrence Crowl
> > On 8/2/07, Paul E. McKenney <paulmck at linux.vnet.ibm.com> wrote:
> > > How about a "memory_order_unspecified", so that the failure_order
> > > would by default follow the success_order?
> >
> > I don't much like introducing a non-ground value into the
> > memory order enumeration. ...
>
> 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. That is, change:
int atomic_int::compare_swap( int& e, int d,
memory_order r = memory_order_seq_cst,
memory_order w = memory_order_seq_cst);
to
int atomic_int::compare_swap( int& e, int d,
memory_order r, memory_order w );
int atomic_int::compare_swap( int& e, int d )
{
compare_swap( e, d,
memory_order_seq_cst, memory_order_seq_cst );
}
int atomic_int::compare_swap( int& e, int d,
memory_order w )
{
compare_swap( e, d,
w == memory_order_acq_rel ? memory_order_acquire :
w == memory_order_release ? memory_order_relaxed : w,
w );
}
The non-member function forms need both parameters explicit.
--
Lawrence Crowl
More information about the cpp-threads
mailing list