================ Start Lecture #25 ================

6.5.2: Safe States

Avoiding deadlocks given some extra knowledge.

Definition: A state is safe if there one can find an ordering of the processes such that if the processes are run in this order, they will all terminate (assuming none exceeds its claim).

Give an example of all four possibilities. A state that is

  1. Safe and deadlocked
  2. Safe and not deadlocked
  3. Not safe and deadlocked
  4. Not safe and not deadlocked

A manager can determine if a state is safe.

The manager then follows the following procedure called Banker's Algorithms discovered by Dijkstra

  1. If there are no processes remaining, the state is safe.

  2. Seek a process P whose max additional requests is less than what remains (for each resource).
  3. The banker now pretends that P has terminated (since the banker knows that it can guarantee this will happen). Hence the banker pretends that all of P's currently held resources are returned. This makes the banker richer and hence perhaps a process that was not eligible to be chosen as P previously, can now be chosen.

  4. Repeat these steps.

Example 1

processclaimcurrent
X31
Y115
Z1910
total16

Example 2

processclaimcurrent
X31
Y115
Z1912
total18

Assume that Z now requests 2 units and we grant them.

Remark: An unsafe state is not necessarily a deadlocked state. Indeed, if one gets lucky all processes may terminate successfully. A safe state means that the manager can guarantee that no deadlock will occur.

6.5.3: The Banker's Algorithm (Dijkstra) for a Single Resource

The algorithm is simple: Stay in safe states.

6.5.4: The Banker's Algorithm for Multiple Resources

At a high level the algorithm is identical: Stay in safe states.