Boost logo

Boost :

Subject: Re: [boost] Boost.Future & review of C++0x accepted libraries implementations
From: Alexander Terekhov (terekhov_at_[hidden])
Date: 2008-11-22 13:53:14

Anthony Williams wrote:

Thanks for the summary.

Starting with basics, I've read
(N2748: Strong Compare and Exchange)

and I think that n2748's compare_exchange_strong() is very
under-specified regarding intended x86's CAS incarnation:

E.g. (pseudo code, sorry for eventual bugs)

  do {
    loaded = load_reserved();
    if (loaded != expected) { expected = loaded; return false; }
  } while (!store_conditional(desired));
  return true;


  do {
    loaded = load_reserved();
    stored = (result = (loaded == expected)) ? desired : loaded;
  } while (!store_conditional(stored));
  return expected = loaded, result;

The first one may result in 'dangling' reservations (which is OK) and
doesn't attempt to perform a store on comparison failure.

The second one is most closely matching x86's CAS (it always performs a
store, even in failure case).

The first one provides better performance in failure case but can not be
used as a 'fake' RMW to achieve 'write atomicity' visibility on
platforms without write atomicity (like Power).


(But note that in the meantime (post 2005 docs) Intel and AMD both seem
to have declared existence of write atomicity on their platforms. That
is not the case for Power, AFAIK.)

Also, just a thought:

Given all that 'weak' and 'strong' CAS story, why not standardize
something along the lines of

(impl. for CAS/non-native LR(LL)-SC platforms)

  load_reserved_weak() {
    return reserved = load(); // static thread-local variable

  store_conditional_weak(value) {
    return compare_exchange_weak(reserved, value);



Boost list run by bdawes at, gregod at, cpdaniel at, john at