Incorrect Algorithm No. 3: Status Flags Again

CONCEPT: Again we use a shared Boolean array as in Algorithm 2. Each process sets its flag before  testing the other flag, thus avoiding the problem of violating mutual exclusion.

INITIALIZATION:

	typedef char boolean;
	...
	shared boolean flags[n -1];
	...
	flags[i ] = FREE;
	...
	flags[j ] = FREE;
	...
ENTRY PROTOCOL (for Process ):
	/* claim the resource */
	flags[] = BUSY;
-->
	/* wait if the other process is using the resource */
	while (flags[] == BUSY) {
	}
EXIT PROTOCOL (for Process ):
	/* release the resource */
	flags[] = FREE;
ANALYSIS: Suppose Process is interrupted at precisely the point marked by the arrow in the exit protocol. At this point the process has claimed the resource but is not yet sure if it is in use. If Process executes its entry protocol before Process resumes, it will set its own flag, then see the flag for Process and wait. Eventually it will be interrupted while waiting, and Process will resume. Process will see the flag for Process and also wait. Each process is waiting indefinitely for the other; deadlock  has occurred.