ch7 Isra
ch7 Isra
ch7 Isra
Operating System Concepts – 8th Edition,! Silberschatz, Galvin and Gagne ©2009!
Chapter 7: Deadlocks
Operating System Concepts – 8th Edition! 1.2! Silberschatz, Galvin and Gagne ©2009!
Chapter Objectives
Operating System Concepts – 8th Edition! 1.3! Silberschatz, Galvin and Gagne ©2009!
The Deadlock Problem
P0 P1
wait (A); wait(B)
wait (B); wait(A)
Operating System Concepts – 8th Edition! 1.4! Silberschatz, Galvin and Gagne ©2009!
Bridge Crossing Example
Operating System Concepts – 8th Edition! 1.6! Silberschatz, Galvin and Gagne ©2009!
Deadlock Characterization
Operating System Concepts – 8th Edition! 1.7! Silberschatz, Galvin and Gagne ©2009!
Resource-Allocation Graph
Deadlocks can be described in terms of resource-allocation graphs. !
Operating System Concepts – 8th Edition! 1.8! Silberschatz, Galvin and Gagne ©2009!
Resource-Allocation Graph (Cont.)
■ Process
"
■ Resource Type with 4 instances"
"
" Pi!
R j!
■ Pi is holding an instance of Rj!
Pi"
R j!
Operating System Concepts – 8th Edition! 1.9! Silberschatz, Galvin and Gagne ©2009!
Example of a Resource Allocation Graph
Operating System Concepts – 8th Edition! 1.10! Silberschatz, Galvin and Gagne ©2009!
Resource Allocation Graph With A Deadlock
Operating System Concepts – 8th Edition! 1.11! Silberschatz, Galvin and Gagne ©2009!
Graph With A Cycle But No Deadlock
Operating System Concepts – 8th Edition! 1.12! Silberschatz, Galvin and Gagne ©2009!
Basic Facts
Operating System Concepts – 8th Edition! 1.13! Silberschatz, Galvin and Gagne ©2009!
Methods for Handling Deadlocks
Operating System Concepts – 8th Edition! 1.14! Silberschatz, Galvin and Gagne ©2009!
Deadlock Prevention
Operating System Concepts – 8th Edition! 1.16! Silberschatz, Galvin and Gagne ©2009!
Deadlock Avoidance
Operating System Concepts – 8th Edition! 1.17! Silberschatz, Galvin and Gagne ©2009!
Safe State
Operating System Concepts – 8th Edition! 1.18! Silberschatz, Galvin and Gagne ©2009!
Example
■ A system with 12 tape drives and 3 processes"
■ P0 requires 10 tape drives, P1 requires 4 tape drives, P2 requires 9"
Operating System Concepts – 8th Edition! 1.19! Silberschatz, Galvin and Gagne ©2009!
Example
Initially, free=3"
At time To the system in a safe state with seq. <P1,P0,P2>."
9
Free= 1 Free=0 Free=3
Operating System Concepts – 8th Edition! 1.20! Silberschatz, Galvin and Gagne ©2009!
Example
At time T1 suppose P2 requested an additional tape drive, then the sequence
<P1,P0,P2>. Will lead to deadlock, now free=2"
Free= 0
Operating System Concepts – 8th Edition! 1.21! Silberschatz, Galvin and Gagne ©2009!
Basic Facts
■ If a system is in safe
state ⇒ no deadlocks
"
■ If a system is in unsafe
state ⇒ possibility of
deadlock
"
■ Avoidance ⇒ ensure
that a system will
never enter an unsafe
state."
Operating System Concepts – 8th Edition! 1.22! Silberschatz, Galvin and Gagne ©2009!
Avoidance algorithms
Operating System Concepts – 8th Edition! 1.23! Silberschatz, Galvin and Gagne ©2009!
Resource-Allocation Graph Scheme
Operating System Concepts – 8th Edition! 1.24! Silberschatz, Galvin and Gagne ©2009!
Resource-Allocation Graph
Operating System Concepts – 8th Edition! 1.25! Silberschatz, Galvin and Gagne ©2009!
Unsafe State In Resource-Allocation Graph
Operating System Concepts – 8th Edition! 1.26! Silberschatz, Galvin and Gagne ©2009!
Resource-Allocation Graph Algorithm
Operating System Concepts – 8th Edition! 1.27! Silberschatz, Galvin and Gagne ©2009!
Banker’s Algorithm
■ Multiple instances
"
■ Each process must a priori claim maximum use
"
■ When a process requests a resource it may have
to wait until the request can be granted safely."
■ When a process gets all its resources it must
return them in a finite amount of time"
Operating System Concepts – 8th Edition! 1.28! Silberschatz, Galvin and Gagne ©2009!
Data Structures for the Banker’s Algorithm
Operating System Concepts – 8th Edition! 1.29! Silberschatz, Galvin and Gagne ©2009!
Safety Algorithm a working copy of
the available
a vector
resources, of Booleans
which
indicating
will be modifiedwhether a
1. "Let Work and Finish be vectors of length m and n, respectively. particular
during the process
has finished so far
analysis.
Initialize:" in the analysis.
Work = Available !
Finish [i] = false for i = 0, 1, …, n- find
Step2: 1" a process
has not finished, but
2. "Find an i such that both: " could with the given
available working set.
(a) Finish [i] = false"
(b) Needi ≤ Work! Step3: process i
finishing up and
If no such i exists, go to step 4" releasing its
resources back
3. "Work = Work + Allocationi into the work pool. Step4: a safe
Finish[i] = true sequence has
been found.
go to step 2"
4. "If Finish [i] == true for all i, then the system is in a safe state"
Operating System Concepts – 8th Edition! 1.30! Silberschatz, Galvin and Gagne ©2009!
Resource-Request Algorithm for Process Pi
Operating System Concepts – 8th Edition! 1.31! Silberschatz, Galvin and Gagne ©2009!
Example of Banker’s Algorithm
Operating System Concepts – 8th Edition! 1.32! Silberschatz, Galvin and Gagne ©2009!
Example (Cont.)
Operating System Concepts – 8th Edition! 1.33! Silberschatz, Galvin and Gagne ©2009!
Example: P1 Request (1,0,2)
Operating System Concepts – 8th Edition! 1.34! Silberschatz, Galvin and Gagne ©2009!
Recovery from Deadlock: Process Termination
Operating System Concepts – 8th Edition! 1.35! Silberschatz, Galvin and Gagne ©2009!
Recovery from Deadlock: Resource Preemption
Operating System Concepts – 8th Edition! 1.36! Silberschatz, Galvin and Gagne ©2009!
End of Chapter 7
Operating System Concepts – 8th Edition,! Silberschatz, Galvin and Gagne ©2009!