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:
[...]
> http://www.justsoftwaresolutions.co.uk/cplusplus/cplusplus-standards-committee-mailing-october-2008.html

Thanks for the summary.

Starting with basics, I've read

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2748.html
(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;

vs.

  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).

See

http://www.decadentplace.org.uk/pipermail/cpp-threads/2005-September/000610.html

(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);
  }

?

regards,
alexander.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk