Atomically, compares the contents of the memory pointed to by object or by this for equality with that in expected, and if true, replaces the contents of the memory pointed to by object or by this with that in desired, and if false, updates the contents of the memory in expected with the contents of the memory pointed to by object or by this.
http://open-std.org/JTC1/SC22/WG21/docs/papers/2011/n3242.pd...
Atomically compares the object representation of this with the object representation of expected, as if by std::memcmp, and if those are bitwise-equal, replaces the former with desired (performs read-modify-write operation). Otherwise, loads the actual value stored in this into expected (performs load operation). Copying is performed as if by std::memcpy.
http://en.cppreference.com/w/cpp/atomic/atomic/compare_excha...
This is an issue with multi threaded programming. Only way to test is to run stress testing, with various simulated payloads, for minutes at a time, preferably on different cpu architectures.
I've been bit by this before. I sometimes wish you had to mark "reference-of" just like you have to mark "address-of" with &.
It's obvious that blah(&foo) might modify foo, without needing to examine the signature of blah().
The tradeoff is a bit of code clutter when you add a symbol (something like shared.compare_exchange_weak(%oldValue, oldValue * multiplier)), and a violation of DRY, since the information provided by this symbol would be redundant.
What the author wants is something like this:
The other examples have the same problem.