I think it is interesting to point out the difference of compare_exchange_strong and compare_exchange_weak. This is related to shared memory consistency models talks in a previous lecture.[2]
The weak one can fail spuriously, but it can have better performance on LL-SC architectures (nearly anything except x86).[1,3]
When the correctness could be ensured without any change, it is better to use the weak one instead of the strong one. But if you need a loop for the weak one while do not need a loop for the strong one, using the strong one can be more efficient.[1]
I think it is interesting to point out the difference of compare_exchange_strong and compare_exchange_weak. This is related to shared memory consistency models talks in a previous lecture.[2]
The weak one can fail spuriously, but it can have better performance on LL-SC architectures (nearly anything except x86).[1,3]
When the correctness could be ensured without any change, it is better to use the weak one instead of the strong one. But if you need a loop for the weak one while do not need a loop for the strong one, using the strong one can be more efficient.[1]