IT lexicon › Programming › Lamport's bakery algorithm

Lamport's bakery algorithm

Programming På svenska → Updated: 2026-11-16

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.

← Back to the lexicon