Third attempt

In the second attempt, we introduced the variables want that are intended to indicate when a process is in its critical section. However, once a process has successfully completed its await statement, it cannot be prevented from entering its critical section. The state reached after the await but before the assignment to want is effectively part of the critical section, but the value of want does not indicate this fact. The third attempt (Algorithm 3.8) recognizes that the await statement

should be considered part of the critical section by moving the assignment to want to before the await. We leave it as an exercise to construct the state diagram for this algorithm, and to show that no state in the diagram violates mutual exclusion. In Section 4.2, we will use logic to prove deductively that the algorithm satisfies the mutual exclusion property.

Unfortunately, the algorithm can deadlock as shown by the following scenario:

This can also be seen in the following fragment of the state diagram:

In the rightmost state, both process are trying to enter the critical section, but nei- ther will ever do so, which is our definition of deadlock.

The term deadlock is usually associated with a frozen computation where noth- ing whatsoever is being computed; the situation here—a scenario where several processes are actively executing