Previous | Next --- Slide 36 of 44
Back to Lecture Thumbnails
pagerank

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]

  1. http://en.cppreference.com/w/cpp/atomic/atomic/compare_exchange
  2. http://stackoverflow.com/questions/4944771/stdatomic-compare-exchange-weak-vs-compare-exchange-strong
  3. http://cbloomrants.blogspot.com/2011/07/07-14-11-compareexchangestrong-vs.html