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