Title: Deadlock
1Deadlock
2Deadlock
- System Model
- Deadlock Characterization
- Methods for Handling Deadlocks
- Deadlock Prevention
- Deadlock Avoidance
- Deadlock Detection Recovery
3The Deadlock Problem
- A state where a set of processes are blocked
each holding a resource and waiting to acquire a
resource held by another process in the set. - Example Semaphores A and B initialized to 1
- P0 P1
- wait(A) wait(B)
- wait(B) wait(A)
- . ..
4Process 1 Process 2 Process 3 .
. ... Request (resource1) Request
(resource2) Request (resource3) /holding res
1 / /holding res 2 / /holding res 3 /
.. .. .. Request(resource2)
Request(resource3) Request(resource1) . ..
..
5System Model
6Deadlock Characterization
7Resource Allocation Graph
8Resource Allocation Graph (cont.)
9Example of a graph with no cycles
10Example of a graph with a cycle
11Basic Facts
12Methods for handling deadlocks
13Deadlock Prevention
14Deadlock Prevention (cont.)
15Deadlock Avoidance
16Safe State
17Basic Facts
18Banker's Algorithm
19Data Structures for the Banker's Algorithm
20Safety Algorithm
Else if no i can be found where Finishiflase
and Needi lt Work , then the system is in an
unsafe state
21Resource Request Algorithm for Process Pi
22Example of Banker's Algorithm
23Example (cont.)
24Example (cont.) P1 requests (1,0,2)
25Deadlock Detection
- Allow system to enter deadlock state
- Detection Algorithm
- Recovery scheme
26Single Instance of Each Resource Type
- Maintain a resource allocation graph
- Periodically invoke algorithm that searches for
cycles in the graph - If there is a cycle gt set of processes in cycle
are in deadlock
27Deadlock Detection
28RAG Reduction Algorithm
- Given the resource allocation graph of the system
at the current state. Determine if the system is
in deadlock. - 1. if a process is not blocked (i.e. if all
resources the process is requesting to finish its
task are available), then reduce graph by that
process remove the process node from the graph,
return all its allocated resources, and remove
all arrows from and to that process.
29Deadlock Detection--RAG Reduction
30Deadlock Detection--RAG Reduction
- 2. Repeat step 1 until all process node are
removed or the graph can not be reduced any
further. - If a graph can be reduce by all its processes,
then there is no deadlock - If a graph can NOT be completely reduced by all
its processes then the "irreducible" processes
constitute the set of deadlocked processes.
31(No Transcript)
32Deadlock Detection-- Usage
33Recovery From Deadlock
34Recovery From Deadlock