Fall 2000: CS 771/871 Operating Systems

[ Home | Class Roster | Syllabus | Status | Glossary | Search | Course Notes]


Deadlocks (Chapter 3)

DEFINITION: blocked process which can never be unblocked - NOT STARVATION.

Simplest case: Process A has Resource 1 but also needs Resource2 to finish. Process B has Resource 2 but also needs Resource 1 to finish. There is only one copy of each resource.

Can be modeled by (wait-for-graph) WFG. .

Conditions for deadlock

Strategies:

Request Models

Types of Resources:


Wait For Graph

Bi-partite directed graph with the following:

We claim the following invariants should hold.

  1. For every reusable resource, Ri:

  2. For every consumable resource Ri:


The following three things can happen to change the graph:

  1. A process can request a resource

  2. A process can acquire a resource

  3. A process can release a reusable resource

  4. A process can produce a consumable resource

Draw some examples (e.g. figure 3.1) show each kind of change.

Definition:  a process is blocked iff for some resource Rj, the number of request edges exceeds rj.

Definition:  a process is deadlocked iff there is no way to become unblocked

A blocked process is NOT deadlocked if there is a sequence of operations that will unblock it - This does not imply that this sequence will happen. In fact another sequence can lead to this process becoming deadlocked.


Necessary and Sufficient Conditions

Graph Reduction Method: 

For any unblocked process Pi:

  1. For each reusable resource, Rj, delete all edges from Pi to Rj. (that is get and use the resource, then release all copies).

  2. For each consumable resource Rj,

NOTE: after any such reduction, assuming no other requests have happened, then possibly more resources are available. (if not Pi didn't matter).

Repeat

One of two outcomes will occur:

  1. all processes are reduced, no process are left blocked, no deadlock

  2. Some processes are still blocked. and no further reductions can be done.

Definition: A general resource graph is completely reducible if a sequence of reductions deletes all edges in the graph.

Theorem 3.1: A process Pi in NOT deadlocked in a general resource graph iff a sequence of reductions leaves the process in a unblocked state.

Corollary 3.1: A system state is deadlock free if the general resource graph is complete reducible.

Since the choice of which process to reduce is non-deterministic, a given reduction sequence may lead to deadlock.

Since there are n! choices, using this approach to deadlock detection is not efficient.

Corollary 3.1 states a sufficient condition for a process and system state to be deadlock free. It does not give a sufficient condition for deadlock to be present (that is, if the graph is NOT reducible, it is not necessarily true that the system is deadlocked).

Can you give examples?

p/56 first para - what if meaning of near future?


Definition: a state is expedient if all processes having outstanding requests are blocked. (there may be active proceses which are not blocked and have no outstanding requests)

A state that is not expedient can becomes expedient if all grantable resources have been granted.

Definition: a path that starts and ends on the same node is a cycle.

Definition: a node is a sink iff it has only incoming edges.

Definition: a knot is a nonempty set of nodes such that for every node in the knot, all nodes and only nodes in the knot are reachable.

There can be no sinks in a knot. 

graph reduction is the removal of sinks from a graph.

Theorem 3.2: In a general resource graph:

Corollary 3.2: If, in an expedient graph, a node Pi is not a sink and no path lead to a sink, the process Pi is deadlocked. (because Pi is in a knot).

Figure 3.5 shows second condition is not necessary

Can you show that first condition is not sufficient? (see. fig 3.2)


Special cases: single request

Theorem 3.3: An expedient resource graph with single unit requests represents a deadlock iff it contains a knot.

figure 3.5 shows that with  multi requests, a knot is not necessary

Efficient to check, make all ancestors of a sink, a sink (why is this true?)


Special cases: consumable resources only

Definition: a claim-limited graph denotes a state in which

See figure 3.6

Theorem 3.4: a consumable resource only graph is deadlock=free if its claim-limited graph is completely reducible

Deadlock free if a producer is not a consumer??

critical sections fail the claim-limited test but are deadlock free.

 


Special cases: reusable resources only

Theorem 3.5: A system with only reusable resources, then

(and one sequence is all we need test).

Show informal proof

Theorem 3.6: If only a single unit of each resource, then a cycle is a necessary and sufficient condition. for a deadlock.


So what? well you can periodically do deadlock detection and if deadlocked, you can pre-empt.


Deadlock Prevention

In general, these strategies are inefficient


Deadlock Avoidance

Basically use the reducibility property to check safe states (banker's algorithm).

Which is best for distributed systems

Assignment 3: 

Give an example of a general resource graph where one reduction leads to deadlock but another reduces the graph (theorem 3.1)
OR give an example of a general resource graph which is NOT reducible but which does not have a deadlock (p.56 first paragraph)

What is the relevance of deadlocks in distributed system? Give an example where deadlock might occur or argue why it is not likely to happen.

Which techniques in chapter 3 make sense in a distributed environment (if any). Briefly explain.

Guidelines for Assignments: Assignments must be posted on your web sites. Obviously you should not copy another student's assignment and treat it as your own. Assignments are an extension of the class dialog. Basically you get credit for doing an assignment and no credit for not doing it. Really exception answers get extra credit.
Most assignments require only short answers - but they should be well thought out answers showing insight into the problem.

 


Copyright chris wild 2000.
For problems or questions regarding this web contact [Dr. Wild].
Last updated: 11 Oct 2000 .