The Bakery algorithm solves the critical section problem for more than two processes. Its name comes from the way in which a bakery or a deli counter works: customers choose a unique number that is larger than any previously choosen number and are then served in turn. First, some notation:
(a,b)<(c,d) if a<c or if a=c and b<d.
Used to determine the order of processes. Notice that (number[i],i) can be unambigously ranked relative to all other like pairs of process numbers and PIDs.
max(a0,a1,...,an-1) is a number k such that k>=ai for i=0,1,...,n-1 and k=ai for some i, 0<=i<=n-1.