( Latest Revision: Sat Dec 13 10:41:51 PST 2003 )

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

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.

This "solution" was invented, submitted to a scholarly journal, checked by the editor and one or more referees, and none of them realized the algorithm was flawed. The algorithm was published in the journal and it had to be "retracted" when it was later discovered to be incorrect!

(Harris Hyman, Comments on a problem in concurrent programming control, Communications of the ACM, v.9 n.1, p.45, Jan. 1966)

```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.

Here is a timeline:

P1   |    P0
|
1   |              flag[1]==true
2   |
3   |
|    1         flag[0]==true
|    2
|    6
5   |              turn==1
6   |              mutual exclusion has been violated
|
=================================================================
```
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."

The format of your scenario must be just like the example above. In particular, you must provide a time-line diagram like the one above. It must indicate the relative time that each process executes each of the numbered statements in the Protocol function.

To receive any credit at all your timeline must explicitly show, in a step-by-step manner, a sequence of events that:

1. is possible, and
2. results in failure of the bounded waiting condition.