On 09/29/2015 04:21 PM, Sandra Loosemore wrote: > What is "weak compare_exchange", and what is "the strong variation", and > how do they differ in terms of behavior?
It's in C++11 29.6.5: Remark: The weak compare-and-exchange operations may fail spuriously, that is, return false while leaving the contents of memory pointed to by expected before the operation is the same that same as that of the object and the same as that of expected after the operation. [ Note: This spurious failure enables implementation of compare-and-exchange on a broader class of machines, e.g., load- locked store-conditional machines. A consequence of spurious failure is that nearly all uses of weak compare-and-exchange will be in a loop. When a compare-and-exchange is in a loop, the weak version will yield better performance on some platforms. When a weak compare-and-exchange would require a loop and a strong one would not, the strong one is preferable. — end note ] The classic use of this is for shared counters: you don't care if you miss an occasional count but you don't want the counter to go backwards. Whether we should replicate all of the C++11 language is perhaps something we should discuss. Andrew.