resource graph for the OR resource request model.
For deadlock in the AND-OR model, no simple way exists of describing it. Generally, the presence of a knot after applying the algorithm to the OR model first and then subsequently applying the algorithm to the AND model and finding a cycle is an indication that deadlock is present.
The following sections present two deadlock detection algorithms-one for the single resource request model and one for the AND resource request model-to illustrate deadlock detection in practice.
For node
The deadlock detection algorithm for systems with a single instance of each resource type, and tasks making resource requests following the single resource request model, is based on the graph theory. The idea is to find cycles in the resource allocation graph, which represents the circular-wait condition, indicating the existence of deadlocks.
Figure 16.3 shows the resource allocation graph. The graph represents the following:
· a circle represents a resource,
· a square represents a task or thread of execution,
· an arrow going from a task to a resource indicates that the task wants the resource, and
· an arrow going from a resource to a task indicates that the task currently holds the resource.
Figure 16.3: Current state of resource allocations and requests.
In the following discussions,
1. Make a list of all the nodes,
2. Pick a node from
3. Insert the node into
4. Check whether any un-traversed outgoing arcs from this node exist. If all of the arcs are traversed, go to step 6.
5. Choose an un-traversed outgoing arc originating from the node and mark the arc as traversed. Follow the chosen arc to the new node and return to step 3.
6. At this stage, a path in the graph terminates, and no deadlocks exist. If more than one entry is in
7. If the list
The actual implementation from step 3 to step 6 translates into a depth first search of the directed graph.
Applying this algorithm to the system depicted in Figure 16.3 provides the following:
Step 1:
Step 2:
Step 3:
Step 4: R1 has one outgoing arc
Step 5: Mark the arc; reaches node T1; go back to step 3
Step 3:
The algorithm continues from step 3 to step 5 and reiterates until it reaches node T3, in which the list
Step 4: T6 does not have any outgoing arcs; continue to step 6
Step 6: Remove T6 from the list
Step 4: Pick the unmarked leftward arc at R5
Step 5: Mark the arc; reaches node T5; return to step 3
Step 3:
Step 4: Pick the only outgoing arc at T5
Step 5: Mark the arc; reaches node R3; go back to step 3
Step 3:
Step 4: Pick the only outgoing arc at R3
Step 5: Mark the arc; reaches node T1; go back to step 3
Step 3:
The deadlock set is comprised of the entire nodes enclosed by the two occurrences of node T1 inclusively. Therefore, the discovered deadlock set is {T1, R2, T2, R4, T3, R5, T5, R3}. One thing worth noting is that the algorithm detects deadlocks if any exist. Which deadlock is detected first depends on the structure of the graph. Closer examination of the resource graph reveals that another deadlock exists. That deadlock set is {R2, T2, R4, T3}. At node T3 if the upward arc is chosen first instead of the downward arc, this later deadlock occurrence would be discovered, and the algorithm would terminate much sooner.
The deadlock detection algorithm takes a different approach for systems with multiple instances of each resource type, and tasks make resource requests following the AND model. An underlying assumption is that a resource allocation system is present. The
Each row of tables C and D represents a task T. Each column of tables C and D is associated with a resource type. C is the resource allocation table representing resources already allocated. D is the resource demand table representing additional resources required by the tasks.
N = Total System Resources Table | N1 | N2 |