The Bakery Algorithm
Generalization for n processes.
Each process has an id. Ids are ordered.
Before entering its critical section, a process receives a number. The holder of the smallest number enters its critical section.
Tie breaker is done using the process id: if processes i and j hold the same number and i < j then i enters first.