Deadlock

These topics are from Chapters 3 (Deadlock) in Advanced Concepts in OS.

Types of Resources

What are examples of each type of resource?

When is a set of processes deadlocked?

What are the fundamental causes of deadlock?

How can we deal with deadlock?

Fundamental Causes of Deadlock

All these conditions are necessary for deadlock to occur.
Hence, by preventing any one of these we prevent deadlock.

Deadlock Handling Strategies

What is the difference between prevention and avoidance?

What are examples of deadlock prevention?

Deadlock Avoidance

Process P1:
request(R1); ... request(R2); ... release(R2); release(R1);

Process P2:
request(R2); ... request(R1); ... release(R1); release(R2);

The Banker's Algorithm is an example of a well known deadlock avoidance algorithm

Deadlock Prevention

Wait-For Graphs (WFG)

Nodes correspond to processes (only).

There is an edge from process P1 to process P2 iff P1 is blocked waiting for P2 to release some resource.

Single-Unit Resource Allocation Graphs

Nodes correspond to processes and resources.

There is a request edge from process P to resource R iff P is blocked waiting for an allocation of R.

There is an assignment edge from resource R to process P iff P is holding an allocation of R.

How do we model multi-unit resources?

Multiunit Resource Allocation Graphs


General Resource System

A system state consists of:

General Resource Graph

Bipartite directed graph

What is a bipartite graph?

Give examples of graphs, operations on graphs, deadlock, and safe/unsafe states.

Request Models

What is a sufficient condition for deadlock in each of these models?

Deadlock Conditions in WFG

Cycle is always a necessary condition for deadlock

A cycle is not a sufficient condition for deadlock in multiunit models.

What is a Knot?

A strongly connected subgraph of a directed graph, such that starting from any node in the subset it is impossible to leave the knot by following the edges of the graph.

A cycle with no deadlock, and no knot.

A knot is a sufficient condition for deadlock

A knot is not a necessary condition for deadlock



Conditions on General Resource Graph

What is the relationship between a system state and a GRG?

Can you describe an algorithm for detecting a deadlock?

Operations on General Resource Graph


Graph Reduction

Models a most favorable possible (optimistic) continuation of execution from the current system state.

while there is an unblocked process Pi:

  1. For each request edge (Pi, Rj), remove the request edge and decrement the corresponding count rj. This corresponds to satisfying the request.
  2. For each allocation edge (Rj, Pi), remove the allocation edge and increment the corresponding count rj. This corresponds to releasing the allocation.
  3. For each consumable resource production edge (Pi, Rj), remove the producer edge from the graph, and set rj to infinity. This corresponds to assuming Pi produces as many units of Rj as may be required by other processes.

There is deadlock iff the remaining graph is non-null





Practicality of GRG Reduction

Expedient States

A state is expedient iff all processes having outstanding requests are blocked, i.e. all grantable requests have been granted.

Note: A system must eventually get to one of these states if it is deadlocked.

Theorem In a GRG,

This still leaves a gap. That is, the existence of a cycle is necessary but not sufficient, and the existence of a knot is sufficient but not necessary.