Compare-and-Swap and Conditional Atomic Updates

Tie an update to the value observed at a location and reuse the result of a failed attempt to reconsider the transition.

Source
Anbloq
Language
English
Created
Updated
Chapters
2
Reading time
1 min
In this article2 chapters
  1. A conditional update has one indivisible check and effect
  2. Equality of bits may not establish equality of history

A conditional update has one indivisible check and effect

Compare-and-swap tests a location against an expected value and applies a replacement only if the comparison succeeds. For a simple counter, read \(x\), attempt to replace \(x\) by \(x+1\), and retry with a current value on a mismatch. If two increments both start from ten, at most one conditional update for expected ten succeeds, assuming no wraparound in this example.

Equality of bits may not establish equality of history

A value might change away and back before comparison. Whether that matters depends on the invariant. A pure monotone counter and a structure referencing reused objects need different proofs. Versioned state and ABA explore this distinction. Linearization points identify the instant a successful operation takes effect, while memory-order rules still govern data around the operation.[1][2]

References

  1. Maurice Herlihy and Nir Shavit, The Art of Multiprocessor Programming ↩
  2. ISO C++ Working Draft, Order and Consistency ↩