Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
$
System Model
Deadlock Characterization
Methods for Handling Deadlocks
Deadlock Prevention
Deadlock Avoidance
Deadlock Detection
Recovery from Deadlock
& %
Combined Approach to Deadlock Handling
' $
Operating System Concepts 7.1 Silberschatz and Galvin
1998
c
& %
P0 P1
wait(A); wait(B)
wait(B); wait(A)
& %
Several cars may have to be backed up if a deadlock occurs.
Starvation is possible.
' $
Operating System Concepts 7.3 Silberschatz and Galvin
1998
c
System Model
Resource types R1 , R2 , . . . , Rm
&
Operating System Concepts 7.4 Silberschatz and Galvin
1998
c
%
' Deadlock Characterization
$
Deadlock can arise if four conditions hold simultaneously.
Mutual exclusion: only one process at a time can use a
resource.
Hold and wait: a process holding at least one resource is
waiting to acquire additional resources held by other
processes.
No preemption: a resource can be released only voluntarily
by the process holding it, after that process has completed its
task.
& %
Circular wait: there exists a set {P0 , P1 , ..., Pn } of waiting
processes such that P0 is waiting for a resource that is held by
P1 , P1 is waiting for a resource that is held by P2 , ..., Pn1 is
waiting for a resource that is held by Pn , and Pn is waiting for a
resource that is held by P0 .
' $
Operating System Concepts 7.5 Silberschatz and Galvin
1998
c
Resource-Allocation Graph
&
Operating System Concepts 7.6 Silberschatz and Galvin
1998
c
%
' Resource-Allocation Graph (Cont.)
$
Process
Pi requests instance of Rj
Pi
Rj
& %
Pi is holding an instance of Rj
Pi
Rj
' $
Operating System Concepts 7.7 Silberschatz and Galvin
1998
c
R1 R3
P1 P2 P3
&
Operating System Concepts
R2
7.8
R4
P3
P1
R2
& %
P4
' $
Operating System Concepts 7.9 Silberschatz and Galvin
1998
c
Basic Facts
&
Operating System Concepts 7.10 Silberschatz and Galvin
1998
c
%
' Methods for Handling Deadlocks
$
Ensure that the system will never enter a deadlock state.
Allow the system to enter a deadlock state and then recover.
Ignore the problem and pretend that deadlocks never occur in
the system; used by most operating systems, including UNIX.
& %
' $
Operating System Concepts 7.11 Silberschatz and Galvin
1998
c
Deadlock Prevention
& %
Low resource utilization; starvation possible.
& %
Circular Wait impose a total ordering of all resource types,
and require that each process requests resources in an
increasing order of enumeration.
' $
Operating System Concepts 7.13 Silberschatz and Galvin
1998
c
Deadlock Avoidance
& %
and allocated resources, and the maximum demands of the
processes.
& %
can wait until all Pj have finished.
When Pj is finished, Pi can obtain needed resources,
execute, return allocated resources, and terminate.
When Pi terminates, Pi +1 can obtain its needed resources,
and so on.
' $
Operating System Concepts 7.15 Silberschatz and Galvin
1998
c
Basic Facts
&
Operating System Concepts 7.16 Silberschatz and Galvin
1998
c
%
' Resource-Allocation Graph Algorithm
$
Claim edge Pi Rj indicates that process Pi may request
resource Rj ; represented by a dashed line.
Claim edge converts to request edge when a process requests
a resource.
When a resource is released by a process, assignment edge
reconverts to a claim edge.
Resources must be claimed a priori in the system.
& %
' $
Operating System Concepts 7.17 Silberschatz and Galvin
1998
c
Bankers Algorithm
Multiple instances.
Each process must a priori claim maximum use.
When a process requests a resource it may have to wait.
When a process gets all its resources it must return them in a
finite amount of time.
&
Operating System Concepts 7.18 Silberschatz and Galvin
1998
c
%
' Data Structures for the Bankers Algorithm
$
Let n = number of processes, and m = number of resource types.
& %
instances of Rj to complete its task.
' $
Operating System Concepts 7.19 Silberschatz and Galvin
1998
c
Safety Algorithm
& %
Finish[i] := true
go to step 2.
4. If Finish[i] = true for all i, then the system is in a safe state.
& %
Allocationi := Allocationi + Requesti ;
Needi := Needi Requesti ;
If safe the resources are allocated to Pi .
If unsafe Pi must wait, and the old resource-allocation
state is restored.
' $
Operating System Concepts 7.21 Silberschatz and Galvin
1998
c
& %
P2 302 902
P3 211 222
P4 002 433
ABC
P0 743
P1 122
P2 600
P3 011
& %
P4 431
' $
Operating System Concepts 7.23 Silberschatz and Galvin
1998
c
& %
Executing safety algorithm shows that sequence <P1 , P3 , P4 ,
P0 , P2 > satisfies safety requirement.
Can request for (3,3,0) by P4 be granted?
Can request for (0,2,0) by P0 be granted?
& %
' $
Operating System Concepts 7.25 Silberschatz and Galvin
1998
c
&
Operating System Concepts 7.26 Silberschatz and Galvin
1998
c
%
' Several Instances of a Resource Type
$
Data Structures
& %
' $
Operating System Concepts 7.27 Silberschatz and Galvin
1998
c
Detection Algorithm
& %
If no such i exists, go to step 4.
& %
' $
Operating System Concepts 7.29 Silberschatz and Galvin
1998
c
& %
P3 211 100
P4 002 002
ABC
P0 000
P1 202
P2 001
P3 100
P4 002
& %
State of system?
Can reclaim resources held by process P0 , but insufficient
resources to fulfill other processes requests.
Deadlock exists, consisting of processes P1 , P2 , P3 , and P4 .
' $
Operating System Concepts 7.31 Silberschatz and Galvin
1998
c
Detection-Algorithm Usage
&
Operating System Concepts 7.32 Silberschatz and Galvin
1998
c
%
' Recovery from Deadlock: Process Termination
$
Abort all deadlocked processes.
Abort one process at a time until the deadlock cycle is
eliminated.
In which order should we choose to abort?
Priority of the process.
How long process has computed, and how much longer to
completion.
Resources the process has used.
& %
Resources process needs to complete.
How many processes will need to be terminated.
Is process interactive or batch?
' $
Operating System Concepts 7.33 Silberschatz and Galvin
1998
c
&
Operating System Concepts 7.34 Silberschatz and Galvin
1998
c
%
' Combined Approach to Deadlock Handling
$
Combine the three basic approaches
prevention
avoidance
detection
allowing the use of the optimal approach for each class of
resources in the system.
Partition resources into hierarchically ordered classes.
& %
Use most appropriate technique for handling deadlocks within
each class.