Chapter 7 Deadlock
Chapter 7 Deadlock
Chapter 7 Deadlock
Chapter 7: Deadlocks
System Model
Deadlock Characterization
Methods for Handling Deadlocks
Deadlock Prevention
Deadlock Avoidance
Deadlock Detection
Recovery from Deadlock
Chapter Objectives
Process
Pi requests instance of Rj
Pi
Rj
Pi is holding an instance of Rj
Pi
Rj
Example of a Resource Allocation Graph
Resource Allocation Graph With A Deadlock
Graph With A Cycle But No Deadlock
Basic Facts
No Preemption –
If a process that is holding some resources requests
another resource that cannot be immediately allocated to
it, then all resources currently being held are released
Preempted resources are added to the list of resources
for which the process is waiting
Process will be restarted only when it can regain its old
resources, as well as the new ones that it is requesting
Assignment Edge
Request Edge
Multiple instances
4. If Finish [i] == true for all i, then the system is in a safe state
Resource-Request Algorithm for Process Pi
Requesti = request vector for process Pi. If Requesti [j] = k
then process Pi wants k instances of resource type Rj
1. If Requesti Needi go to step 2. Otherwise, raise error
condition, since process has exceeded its maximum claim
2. If Requesti Available, go to step 3. Otherwise Pi must
wait, since resources are not available
3. Pretend to allocate requested resources to Pi by modifying
the state as follows:
Available = Available – Requesti;
Allocationi = Allocationi + Requesti;
Needi = Needi – Requesti;
If safe the resources are allocated to Pi
Ifunsafe Pi must wait, and the old resource-allocation
state is restored
Example of Banker’s Algorithm
Executing safety algorithm shows that sequence < P1, P3, P4, P0, P2>
satisfies safety requirement
Detection algorithm
Recovery scheme
Single Instance of Each Resource Type
Sequence <P0, P2, P3, P1, P4> will result in Finish[i] = true for all i
Example (Cont.)
P2 requests an additional instance of type C
Request
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
Detection-Algorithm Usage
When, and how often, to invoke depends on:
How often a deadlock is likely to occur?
How many processes will need to be rolled back?
one for each disjoint cycle
Rollback – return to some safe state, restart process for that state