
Alexander Terekhov <terekhov@web.de> writes:
Anthony Williams wrote: [...]
http://www.justsoftwaresolutions.co.uk/cplusplus/cplusplus-standards-committ...
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....
(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.)
Thanks. I had been concerned about the ordering guarantees on failure, but hadn't got round to raising an issue. I'll do so today.
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); }
Are you suggesting these be added to the atomic types? Interesting. I'll raise that separately and see what people say. Anthony -- Anthony Williams Author of C++ Concurrency in Action | http://www.manning.com/williams Custom Software Development | http://www.justsoftwaresolutions.co.uk Just Software Solutions Ltd, Registered in England, Company Number 5478976. Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK