The author reminisces about a memorable undergrad class on multiprocessor synchronization, starting with consensus numbers and ending with lock-free data structures in Java. They struggled when translating these concepts to C, realizing Java’s support for multithreaded correctness. The article introduces acquire-release semantics and reveals a bug in a lock-free queue implementation due to non-linearizable memory on CPUs. The author outlines how fences can maintain memory order, fixing reordering issues in the queue. A second bug in the queue, causing null returns despite successful poll, is explained and resolved using fences. The article highlights subtle CPU-induced bugs in multithreaded code and the importance of memory ordering guarantees.
https://davekilian.com/acquire-release.html