[cpp-threads] Failed compare-and-swap

Paul E. McKenney paulmck at linux.vnet.ibm.com
Tue Jul 31 21:13:28 BST 2007


On Tue, Jul 31, 2007 at 09:18:56PM +0200, Alexander Terekhov wrote:
> On 7/31/07, Herb Sutter <hsutter at microsoft.com> wrote:
> [...]
> > So the question here is whether we want to support the technique of using a CAS
> > to perform an atomic read. Do we? We can say yes by returning the old value, or
> > no by returning a succeeded/failed bool.
> 
> Model it on load-locked/reserved+compare+store-conditional and let
> application specify both leading and trailing unidirectional
> hoist/sink constraints with an option to specify different trailing
> constraints for success and failure on compare. And let it also
> indicate whether validation (store of loaded value) is needed on
> compare failure as well.

That makes quite a bit of sense, at first glance, anyway.  Then the
unadorned version (atomic_compare_swap() in N2324) would be sequentially
consistent in either case, and the atomic_compare_swap_explicit() would
take an additional memory_order argument for the failure case:

bool atomic_compare_swap_explicit( volatile atomic_bool*, bool*, bool,
                                   memory_order, memory_order );

Implementations are of course free to provide stronger ordering than
requested, if desired.

Seem reasonable?

						Thanx, Paul



More information about the cpp-threads mailing list