COMP3891

Deadlock

Resources

Examples of computer resources:

Processes need access to resources in a reasonable order.

Formal Definition of Deadlock

A set of proceses is deadlocked if each process in the set is waiting for an event that only another process in the set can cause.

Conditions for Deadlock

Deadlock Prevention

Must attack one of the four deadlock conditions.

Attacking Mutual Exclusion

Not viable - some resources are intrinsically not shareable.

Attacking Hold and Wait

Attacking No-Preemption

Attacking Circular Wait

Deadlock Detection and Recovery

Instead of preventing deadlocks, detect when a system is deadlock and recover from it.

Detection With One Resource of Each Type

Deadlock found when there is a cycle in the graph.

Detection With Multiple Resource of Each Type

Algorithm:

  1. Lock for an unmarked process Pi, for which the i-th row of R is less than or equal to A.
  2. If found, add the i-th row of C to A, and mark Pi. Repeat from step 1.
  3. If no such process exists, terminate.

Recovery:

Deadlock Avoidance

Avoid deadlocks ahead of time.

Resource Trajectory

If a trajectory has no choice but to enter the shaded boxes, then it is deadlocked.

Trajectories must be chosen to completely avoid unsafe regions.

Safe and Unsafe States

A state is safe if:

Note: