This is the version of Peterson's synchronization algorithm for 2 processes, process 0 and process 1. As seen in the text, the algorithm can easily be extended to support any number of processes (the Bakery algorithm on page 163). The two processes using the code below repeatedly enter their critical sections, do their critical sections and then leave their critical sections. Assume that when i == 0, j == 1 and when j == 0, i == 1. GLOBALS: var flag: array [0..1] of boolean; turn: 0..1; repeat /* try and enter critical section */ flag[i] := true; turn := j; while ( flag [j] and turn == j ) do no_op ( ); /*spin */ /******** do critical section ********/ /* leave critical section */ flag [i] := false; until false;