var enter1, enter2 = false : boolean ;
turn = 1 : integer ; {i.e. P1}
Process P1
loop
{entry protocol}
enter1 := true; {announce intent to enter}
turn := 2 ; {set priority to P2}
while enter2 and turn=2
do nothing ; {wait if other process in CS}
{critical section}
enter1 := false {exit protocol}
end
end
Process P2
loop
{entry protocol}
enter2 := true ; {announce intent to enter}
turn := 1 ; {set priority to other process}
while enter1 and turn=1
do nothing ; {wait if other process is in CS}
{critical section}
enter2 := false ; {exit protocol}
end
end
From Example 1 :
From Example 2 :
Aim to achieve synchronisation : simplest way -