Deadlock Chapter 10 12282021 A Berrached cms uhd
Deadlock Chapter 10 12/28/2021 A. Berrached: : cms: : uhd 1
Deadlock • System Model • Deadlock Characterization • Methods for Handling Deadlocks – Deadlock Prevention – Deadlock Avoidance – Deadlock Detection & Recovery 12/28/2021 A. Berrached: : cms: : uhd 2
The 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 12/28/2021 P 0: wait(A); P 1: wait(B); …. wait(A); …. . A. Berrached: : cms: : uhd 3
Process 1 Process 2 Process 3 …. …. . . Request (resource 1); /*holding res 1 */ …. . Request (resource 2); /*holding res 2 */ …. . Request (resource 3); /*holding res 3 */ …. . Request(resource 2) …. Request(resource 3); …. . Request(resource 1); …. . 12/28/2021 A. Berrached: : cms: : uhd 4
System Model 12/28/2021 A. Berrached: : cms: : uhd 5
Deadlock Characterization 12/28/2021 A. Berrached: : cms: : uhd 6
Resource Allocation Graph 12/28/2021 A. Berrached: : cms: : uhd 7
Resource Allocation Graph (cont. ) 12/28/2021 A. Berrached: : cms: : uhd 8
Example of a graph with no cycles 12/28/2021 A. Berrached: : cms: : uhd 9
Example of a graph with a cycle 12/28/2021 A. Berrached: : cms: : uhd 10
Basic Facts 12/28/2021 A. Berrached: : cms: : uhd 11
Methods for handling deadlocks 12/28/2021 A. Berrached: : cms: : uhd 12
Deadlock Prevention 12/28/2021 A. Berrached: : cms: : uhd 13
Deadlock Prevention (cont. ) 12/28/2021 A. Berrached: : cms: : uhd 14
Deadlock Avoidance 12/28/2021 A. Berrached: : cms: : uhd 15
Safe State 12/28/2021 A. Berrached: : cms: : uhd 16
Basic Facts 12/28/2021 A. Berrached: : cms: : uhd 17
Banker's Algorithm 12/28/2021 A. Berrached: : cms: : uhd 18
Data Structures for the Banker's Algorithm 12/28/2021 A. Berrached: : cms: : uhd 19
Safety Algorithm Else if no i can be found where Finish[i]=flase and Needi <= Work , then the system is in an unsafe state 12/28/2021 A. Berrached: : cms: : uhd 20
Resource Request Algorithm for Process Pi 12/28/2021 A. Berrached: : cms: : uhd 21
Example of Banker's Algorithm 12/28/2021 A. Berrached: : cms: : uhd 22
Example (cont. ) 12/28/2021 A. Berrached: : cms: : uhd 23
Example (cont. ): P 1 requests (1, 0, 2) 12/28/2021 A. Berrached: : cms: : uhd 24
Deadlock Detection • Allow system to enter deadlock state • Detection Algorithm • Recovery scheme 12/28/2021 A. Berrached: : cms: : uhd 25
Single 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 ==> set of processes in cycle are in deadlock 12/28/2021 A. Berrached: : cms: : uhd 26
Deadlock Detection 12/28/2021 A. Berrached: : cms: : uhd 27
RAG 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. 12/28/2021 A. Berrached: : cms: : uhd 28
Deadlock Detection--RAG Reduction 12/28/2021 A. Berrached: : cms: : uhd 29
Deadlock 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. 12/28/2021 A. Berrached: : cms: : uhd 30
12/28/2021 A. Berrached: : cms: : uhd 31
Deadlock Detection-- Usage 12/28/2021 A. Berrached: : cms: : uhd 32
Recovery From Deadlock 12/28/2021 A. Berrached: : cms: : uhd 33
Recovery From Deadlock 12/28/2021 A. Berrached: : cms: : uhd 34
- Slides: 34