Apex › Systems & OS

Lamport's bakery algorithm

Mutual exclusion using only atomic reads and writes — no test-and-set, no hardware lock. Threads take a bakery ticket one higher than anyone waiting and are served lowest-number-first; since taking a number isn't atomic, ties can happen and are broken by thread id, giving a total order with exactly one winner. Choose how the threads arrive and watch who enters the critical section.

More in Systems & OS