© Thomas Kunz 2000
SCE 574
210
Software Solutions:
Algorithm 3
äInitialization: flag[0]:=flag[1]:=false turn:= 0 or 1 äWillingness to enter CS specified by flag[i]:=true äIf both processes attempt to enter their CS simultaneously, only one turn value will last äExit section: specifies that Pi is unwilling to enter CS äThis algorithm is also known as “Peterson’s Algorithm”
Process Pi:
repeat
  flag[i]:=true;
  turn:=j;
  do {} while
  (flag[j]and turn=j);
     CS
  flag[i]:=false;
     RS
forever