Download presentation
Presentation is loading. Please wait.
1
Deadlocks CPE 261403 - Operating Systems http://mango.e-cpe.org/
3
Conditions of a Deadlock (7.2.1) Mutual exclusion Is holding a resource that cannot be shared Hold and wait Is waiting for resources while holding others No preemption Cannot be forced to release the acquired resources Circular wait
4
Which of these are in a deadlock?
5
Methods for Handling Deadlocks Never allow a deadlock state (Preventions Or Avoids Deadlocks) Allow deadlock and then recover (Deadlock Detection) Ignore the problem
6
Deadlock Prevention (7.4) Prevent deadlock conditions from occurring Mutual exclusion Hold and wait No preemption Circular wait
7
Prevention Techniques Hold and wait Never hold a resource unless all are available All or nothing Divide into functional segments OR
8
No preemption Terminate process and roll it back to a known good state Printing Terminate Must roll-back in order to resume properly
9
Circular wait Assign an ID to each resource. Enforce resources to be reserved only on an ascending order ID = 1ID = 2ID = 3
10
Deadlock Avoidance (7.5) Figure 7.5
11
Example Max NeedsNeeds at T0 (safe) Needs at T1 (unsafe) P0422 P11055 P2923 Total number of resources = 12
12
Resource Allocation Graph SafeUnsafe
13
Banker’s Algorithm Available: Vector of length m. If available [j] = k, there are k instances of resource type R j available. Max: n x m matrix. If Max [i,j] = k, then process P i may request at most k instances of resource type R j. Allocation: n x m matrix. If Allocation[i,j] = k then P i is currently allocated k instances of R j. Need: n x m matrix. If Need[i,j] = k, then P i may need k more instances of R j to complete its task. Need [i,j] = Max[i,j] – Allocation [i,j]. Let n = number of processes, and m = number of resources types.
14
Example ABC 753 322 902 222 433 P0 P1 P2 P3 P4 ABC 010 200 302 211 002 MAXAllocation 3 resource types: A (10 instances), B (5instances), and C (7 instances). Time T0
15
Safety Algorithm Available NeedFinish P0 P1 P2 P3 P4 R1R2R3
16
Safety Algorithm 7-0=75-1=43-0=3 3-2=12-0=2 9-3=60-0=02-2=0 2-1=1 4-0=43-0=33-2=1 332 Available NeedFinish P0 P1 P2 P3 P4 R1R2R3
17
Are we safe?? 743 122 600 011 431 332 Available NeedFinish P0 P1 P2 P3 P4 R1R2R3
18
Example (Cont.) The system is in a safe state since the sequence satisfies safety criteria.
19
Process P1 makes a request for: 1 instance of A 2 instance of C Request Vector = (1,0,2) Should we allow this request?
20
Safety Algorithm after (1,0,2) request 743 122 600 011 431 332 Work NeedFinish P0 P1 P2 P3 P4 R1R2R3
21
Example: P 1 Request (1,0,2) Executing safety algorithm shows that sequence satisfies safety requirement.
22
Please analyze these questions Can request for (3,3,0) by P 4 be granted? Can request for (0,2,0) by P 0 be granted?
23
Deadlock Detection (7.6)
24
Wait-for Graphs (single instance system only) Resource-Allocation GraphCorresponding wait-for graph
25
Wait-for Graph does not work with multiple instance resources
26
Banker’s Algorithm as a deadlock detection tool for multiple instance systems
27
Deadlock Recovery (7.7)
28
Process Termination Abort all deadlock processes Abort one at a time until deadlock cycle is eliminated
29
Resource Preemption Selecting a victim – minimize cost. Rollback – return to some safe state, restart process for that state. Starvation – same process may always be picked as victim, include number of rollback in cost factor.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.