The first known correct software solution
to critical section problem for two process was developed by
Dekker. The two processes, P0 and P1, share the following variables:
Boolean flag [2]; /* initially False */
Int turn;
The structure of process Pi (i = =0 or 1), with Pj (j= =0 or 1) being the other process, is
Do
{
Flag[i] = true;
While (flag [j])
{
if (turn = = j)
{
flag [i] = false;
while ( turn = = j) {};
flag [i] = true;
}
}
Critical Section
Turn = j;
Flag [i] = false;
Remainder section
} While (TRUE)
Prove that the algorithm satisfies all the three requirements for
the critical section problem.