Two threads run the CAS loop — read → compute → compare-and-swap → retry — on one shared variable. Watch one thread succeed and the other fail and retry. Switch to ABA mode to see a value go A→B→A and fool a naive CAS — then enable the version tag to defeat it.
| Operation | Effect (atomic) | Returns | Progress |
|---|---|---|---|
load | read the value | value | wait-free |
store | write the value | — | wait-free |
fetch-add(d) | v += d | old v | wait-free |
exchange(x) | v = x | old v | wait-free |
CAS(exp,new) | if v==exp then v=new | success? | — |
CAS loop | read, compute, CAS, retry | — | lock-free |