Hyman's Incorrect "Solution" to the Critical Section Problem


/////////////////////////
  HYMAN'S "SOLUTION"
/////////////////////////

This is an example of something that appears to be an adequate
solution to the critical section problem for two processes, yet
which does not really meet the requirements either of mutual
exclusion or bounded waiting.

initially turn=0, flag[0]=flag[1]=false ;
        
Each of two processes, P0 and P1 executes the code below, P0
executes Protocol(0,1), and P1 executes Protocol(1,0).

void Protocol (int me, int you)
{
        do 
        {
1.        flag[me] = true ;
2.        while (turn != me)
          {
3.             while (flag[you])
4.               /* do nothing */ ;
5.             turn = me
          }
6.        CriticalSection(me) ;
7.        flag[me] = false ;
8.        RemainderSection(me) ;
        } while (true) ;
}

Here is a "scenario" that shows one way in which mutual
exclusion can fail when two processes P0 and P1 execute
procedure "Protocol" above:
=================================================================
initially turn=0, flag[0]=flag[1]=false ;

P1 executes 1, 2, 3
(since flag[0] was false, the next
 instruction P1 will execute is 5.)

P0 then executes 1, 2, 6

P1 executes 5, 6

and now P0 and P1 are both in their critical sections.
=================================================================

Your assignment: Figure out and write another "scenario."  This
scenario must show instead that it is possible for the bounded
waiting condition to fail if two processes P0 and P1
concurrently execute procedure "Protocol."