[ Home | Class Roster | Syllabus | Status | Glossary | Search | Course Notes]
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:
deadlock avoidance: be cautious, only allow resource acquisition in which it is possible to avoid deadlock
Request Models
Single Unit: only one unit at a time
AND request: many resources simultaneously
OR request: any one of a multiple request
AND/OR request: combines last two above
P-out-of-Q: any P out of Q requested. - generalizes "OR-request"
Types of Resources:
Reusable: e.g. processor, memory
Bi-partite directed graph with the following:
Nonempty set of processes P = (P1,P2,...Pn)
Nonempty set of resources G = (R1,R2,...,Rm), partitioned into two disjoint subsets for reusable and consumable
For every reusable resource Ri, there exists a nonnegative number Ti, denoting the total number of resource Ri available
For every consumable resource Ri, there exists a nonempty subset of processes called the producers of Ri
The Wait-for-Grpha is bi-partite, meaning edges cannot go between nodes of the same type (process to resource or resource to process only)
An edge from a process Pi to a resource Rj is a request edge.
An edge from a reusable resource Rj to a producer Pi is an assignment edge
An edge from a consumable resource Rj to a producer Pi is a producer edge
Let #(A,B) be the number of outgoing edges from A to B
Let #(A,*) be the total number of edges coming from A
There is also a vector (r1,r2,..rm) of the available units of each resource in a particular state.
We claim the following invariants should hold.
For every reusable resource, Ri:
The number of assignment edges, #(Ri,*) <=Ti // impossible if exclusive use
ri = Ti - #(Ri,*) // all accounted for
For All Pj, #(Pj,Ri) + #(Ri,Pj) <= Ti // how to prevent this?
For every consumable resource Ri:
There is an edge from Ri to Pj iff Pj is a producer of Ri
ri >= 0
The following three things can happen to change the graph:
A process can request a resource
A process can acquire a resource
A process can release a reusable resource
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.
Graph Reduction Method:
For any unblocked process Pi:
For each reusable resource, Rj, delete all edges from Pi to Rj. (that is get and use the resource, then release all copies).
For each consumable resource Rj,
Decrement rj by the #(Pi,Rj)
What justifies this step?
If Pi is a producer of Rj, set rj to infinity
Delete all edges from Pi to 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:
all processes are reduced, no process are left blocked, no deadlock
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)
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?)
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.
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.
Acquire all resources at once
higher priority process pre-empt lower
total resource ordering, request in order (no cycles)
In general, these strategies are inefficient
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) 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. |