108
Algorithm 3 (Peterson’s algorithm)
nInitialization: flag[0]:=flag[1]:=false turn:= 0 or 1
nWillingness to enter CS specified by flag[i]:=true
nIf both processes attempt to enter their CS simultaneously, only one turn value will last
nExit section: specifies that Pi is unwilling to enter CS
Process Pi:
repeat
  flag[i]:=true;
  turn:=j;
  do {} while
  (flag[j]and turn=j);
     CS
  flag[i]:=false;
     RS
forever