Lamport's bakery algorithm
A classic lock-free algorithm for mutual exclusion in multithreaded systems that requires no hardware atomic operations.
Leslie Lamport published the bakery algorithm in 1974 as a theoretical proof that mutual exclusion is possible without special atomic instructions—using only reads and writes with ordering guarantees. Threads draw a number like in a bakery queue and are served in order. It is academically elegant but slow in practice due to active waiting and many memory accesses. Modern implementations rely instead on compare-and-swap and memory fences.
The bakery algorithm is important for understanding concurrency theory: it proves that the tools we take for granted today (atomic operations) are not fundamental—they are just extremely practical optimizations over simpler building blocks.