Beruflich Dokumente
Kultur Dokumente
Mutual Exclusion
Shared resources are acquired and used mutually
exclusively
Deadlock Hold and Wait
Each process continues to hold resources already allocated
to it while waiting to acquire new resources
No Preemption
Resources granted to a process can only be released back to
the system after the process finished using it
Circular Waiting
Processes forms a chain in the wait for graph
If a group of processes are blocked on their resource Specify the relationship among processes and
requests that can never be satisfied, then it is a resources
deadlock A directed edge from a process to a resource represents that
the process is requesting for the resource
A directed edge from a resource to a process represents that
the resource is held by the process
P5 F1 P1 F2 P2
F5 P4 F4 P3 F3
1
Deadlock Prevention Deadlock Avoidance
Disallow at least one of the four necessary conditions System grants allocations of resources only if it is
Avoid Mutual Exclusion guaranteed to be deadlock free
Nothing can be done if the resource cannot be shared For a new request requesting for resources
Allow Preemption System pretends to grant the resources
Not all resources can be preempted (e.g., printer) Check whether the new state is safe
Grant the requested resources only if it is safe
Avoid Circular Wait
Safe
Linear ordering on resources
In the future, the system can allocate resources in at least one order
E.g., resources A, B, C, order(A) = 1, order(B) = 2, order(C) = 3 that guarantees free of deadlock
request (C and A) request (A); request (C); Unsafe
Problems: system may (still may not) end up in deadlock situation
Require resource requirement information in advance Problem
Low resource utilization
Need to know resource requirements for all processes in advance
Degradation of concurrency (resources are allocated before it is needed)
2
Bankers Algorithm Bankers Algorithm
3
Bankers Algorithm Example 1 Bankers Algorithm Example 3
4
Deadlock Detection Comparisons
Check safety
Total Alloc Avl Req
P1 P2 P3 P1 P2 P3
R1 2 0 0 1 1 2 0 1 P can get the resources
2
R2 4 0 1 1 2 0 2 1 P2 return resources
R3 2 1 0 0 1 0 1 2
-----------------------------------------------------
R1 2 0 1 1 2 1 No process can get
R2 4 0 1 3 0 1 the resources
R3 2 1 0 1 0 2 Deadlock
----------------------------------------------------- P1 and P3 involved