Download presentation
Presentation is loading. Please wait.
Published byKevin Brown Modified over 8 years ago
1
Deadlocks 12/02/2015
2
What is a deadlock ? System has a finite set of resources. Resource can have one or more instances. Processes compete for resources. Process resource sequence Request Use Release A deadlock is when a process is not able to change state because it is waiting for a resource that will NEVER become available.
3
Deadlock Analogies
4
Deadlock Necessary Conditions Mutual Exclusion Occurs when a resource can only be used by one process at a time Other process has to wait until the resource is released. Hold and Wait A process must be holding at least one resource and waiting to acquire additional resources that are currently being held by other processes. No preemption Resource can only be released voluntarily by the process holding it. Circular wait {P0,P1,….,Pn}
5
Resource-Allocation Graph G = {V,E} V are divided in two groups P={P1,P2,….,Pn} R={R1,R2,…,Rn} R1 R2 R3 R4 P1P2P3 R1 R2 R3 R4 P1P2P3
6
How to handle deadlocks Use a protocol to prevent or avoid deadlocks Allow the system to enter a deadlocked state, detect it, and recover. Ignore the problem and pretend that they never occur.
7
How to handle deadlocks Deadlock prevention Ensures that at least one of the necessary condition cannot hold Deadlock avoidance Requires the operating system be given in advanced additional information concerning which resources a process will request and use during its lifetime. Deadlock Detection Recovery from a Deadlock
8
Deadlock Prevention Mutual Exclusion Hold for non-shareable resources. Some resources are intrinsically non-sharable Hold and Wait Whenever a process request a resource, it doesn’t not hold to any other resources. Protocols All resources are available before execution. Request a process only when it has none. Use the resource and release it before use other. Drawbacks Utilization may be low Starvation
9
Deadlock Prevention No preemption Protocol If a process is holding some resources and request another resource that cannot be allocated. All the resources of the process are preempted. If a process needs a resource to be allocated first check if it is available, then check for resources that are in waiting and preempt the desire resource. Circular wait Impose a total ordering of all resources types and to require that each process request resources in a increase order of enumerations. Let R = {R1,R2,R3,…,Rm} F(Rj) > F(Ri)
10
Deadlock Avoidance Have additional information how about how resources to be request. Deadlock-avoidance algorithms Safe State If the system can allocate resources to each process in some order and still avoid a deadlock. Resource-allocation-graph algorithm Banker’s algorithm
11
Safe State Example 12 Magnetic tape drives Safe State Maximum NeedsCurrent Needs P0105 P1 4 2 P2 92 Unsafe State Maximum NeedsCurrent Needs P0105 P1 4 2 P2 93
12
Resource-Allocation-Graph Algorithm R1 R3 P1 P2 R1 R3 P1 P2
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.