Chapter 1_ Process Deadlocks
Chapter 1_ Process Deadlocks
Process Deadlocks
● Pi requests instance of Rj
P
i
● Pi is holding an instance of Rj Rj
P
i
Rj
Example of a Resource Allocation
Graph 1.3.2
Resource Allocation Graph With A
1.3.2
Deadlock
Graph With A Cycle But No
1.3.2
Deadlock
Basic Facts
1.3.3
● If graph contains no cycles ⇒ no deadlock
● If graph contains a cycle ⇒
● if only one instance per resource type,
then deadlock
● if several instances per resource type, possibility
of deadlock
Methods for Handling
1.4
Deadlocks
● Ensure that the system will never enter a
deadlock state:
● Deadlock prevention
● Deadlock avoidence
● Allow the system to enter a deadlock state and
then recover
● Ignore the problem and pretend that deadlocks never
occur in the system;
Lecture 3
Deadlock
1.5
Prevention
Restrain the ways request can be made
4. If Finish [i] == true for all i, then the system is in a safe state
Resource-Request Algorithm for Process Pi 1.9.
2
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
● If unsafe ⇒ Pi must wait, and the old resource-allocation state
is restored
Example of Banker’s Algorithm 1.9.
2
● 5 processes P0 through
P4; 3 resource types:
A (10 instances), B (5instances), and C (7 instances)
● Snapshot at time T0:
Allocation Max Available
ABC ABC ABC
P0 0 1 0 753 332
P1 2 0 0 322
P2 3 0 2 902
P3 2 1 1 222
P4 0 0 2 433
Example 1.9.
2
●
(Cont.)
The content of the matrix Need is defined to be Max –
Allocation
Need
ABC
P0 7 4 3
P1 1 2 2
P2 6 0 0
P3 0 1 1
P4 4 3 1
● The system is in a safe state since the sequence < P1, P3, P4, P2,
P0> satisfies safety criteria
Example: P1 Request (1,0,2) 1.9.
2
● Check that Request ≤ Available (that is, (1,0,2) ≤ (3,3,2) ⇒ true
Allocation Need Available
ABC ABC ABC
P0 0 1 0 743 230
P1 302 020
P2 3 0 2 600
P3 2 1 1 011
P4 0 0 2 431
● Executing safety algorithm shows that sequence < P1, P3, P4, P0,
P2> satisfies safety requirement
● Detection algorithm
● Recovery scheme
Single Instance of Each Resource Type 1.10.
1
● Maintain wait-for graph
● Nodes are processes
● Pi → Pj if Pi is waiting for Pj
P1 200 202
P2 303 000
P3 211 100
P4 002 002
● Sequence <P0, P2, P3, P1, P4> will result in Finish[i] = true for all
i
Example 1.10.
(Cont.) 3
● P2 requests an additional instance of type C
Request
ABC
P0 0 0 0
P1 2 0 2
P2 0 0 1
P3 1 0 0
P4 0 0 2
● 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 1.10.
4
● 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?
4 one for each disjoint cycle