INITIALIZATION:
typedef char boolean; ... shared boolean flags[n -1]; ... flags[i ] = FREE; ... flags[j ] = FREE; ...ENTRY PROTOCOL (for Process i ):
/* claim the resource */ flags[i ] = BUSY; --> /* wait if the other process is using the resource */ while (flags[j ] == BUSY) { }EXIT PROTOCOL (for Process i ):
/* release the resource */ flags[i ] = FREE;ANALYSIS: Suppose Process i 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 j executes its entry protocol before Process i resumes, it will set its own flag, then see the flag for Process i and wait. Eventually it will be interrupted while waiting, and Process i will resume. Process i will see the flag for Process j and also wait. Each process is waiting indefinitely for the other; deadlock has occurred.