Mutual Exclusion Without Hardware Support
Symptom Two threads increment a shared counter a million times each. The final value is 1,374,522. You know why: the increment is a read, an add, and a write, and the interleavings lose updates. The fix is a lock. But a lock is provided by your runtime, which gets it from the OS, which gets it from a hardware instruction — lock xchg, cmpxchg, ldrex/strex. ...