n Initialization:
flag[0]:=flag[1]:=false
turn:= 0 or 1
n Willingness to enter
CS specified by
flag[i]:=true
n If both processes
attempt to enter their
CS simultaneously,
only one turn value
will last
n Exit 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