Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
SlideShare a Scribd company logo
Concurrency: Deadlock and
Starvation
Roadmap
• Principals of Deadlock
– Deadlock prevention
– Deadlock Avoidance
– Deadlock detection
Deadlock
• A set of processes is deadlocked when
each process in the set is blocked awaiting
an event that can only be triggered by
another blocked process in the set
– Typically involves processes competing for
the same set of resources
• No efficient solution
Potential Deadlock
I need
quad A and
B
I need
quad B
and C
I need
quad C
and B
I need
quad D
and A
Actual Deadlock
HALT until
B is free
HALT until
C is free
HALT until
D is free
HALT until
A is free
Resource Categories
Two general categories of resources:
• Reusable
– can be safely used by only one process at a
time and is not depleted by that use.
• Consumable
– one that can be created (produced) and
destroyed (consumed).
Reusable Resources
• Such as:
– Processors, I/O channels, main and
secondary memory, devices, and data
structures such as files, databases, and
semaphores
• Deadlock occurs if each process holds
one resource and requests the other
Example of
Reuse Deadlock
• Consider two processes that compete for
exclusive access to a disk file D and a
tape drive T.
• Deadlock occurs if each process holds
one resource and requests the other.
Reusable Resources
Example
Consider : p0 p1 q0 q1 p2 q2
Example 2:
Memory Request
• Space is available for allocation of
200Kbytes, and the following sequence of
events occur
• Deadlock occurs if both processes
progress to their second request
P1
. . .
. . .
Request 80 Kbytes;
Request 60 Kbytes;
P2
. . .
. . .
Request 70 Kbytes;
Request 80 Kbytes;
Consumable Resources
• Such as Interrupts, signals, messages,
and information in I/O buffers
• Deadlock may occur if a Receive message
is blocking
• May take a rare combination of events to
cause deadlock
Example of Deadlock
• Consider a pair of processes, in which
each process attempts to receive a
message from the other process and then
send a message to the other process
Resource Allocation
Graphs
• Directed graph that depicts a state of the
system of resources and processes
Conditions for possible Deadlock
• Mutual exclusion
– Only one process may use a resource at a
time
• Hold-and-wait
– A process may hold allocated resources while
awaiting assignment of others
• No pre-emption
– No resource can be forcibly removed form a
process holding it
Actual Deadlock
Requires …
All previous 3 conditions plus:
• Circular wait
– A closed chain of processes exists, such that
each process holds at least one resource
needed by the next process in the chain
Resource Allocation
Graphs of deadlock
Resource Allocation
Graphs
Dealing with Deadlock
• Three general approaches exist for
dealing with deadlock.
– Prevent deadlock
– Avoid deadlock
– Detect Deadlock

More Related Content

Deadlocks1

  • 2. Roadmap • Principals of Deadlock – Deadlock prevention – Deadlock Avoidance – Deadlock detection
  • 3. Deadlock • A set of processes is deadlocked when each process in the set is blocked awaiting an event that can only be triggered by another blocked process in the set – Typically involves processes competing for the same set of resources • No efficient solution
  • 4. Potential Deadlock I need quad A and B I need quad B and C I need quad C and B I need quad D and A
  • 5. Actual Deadlock HALT until B is free HALT until C is free HALT until D is free HALT until A is free
  • 6. Resource Categories Two general categories of resources: • Reusable – can be safely used by only one process at a time and is not depleted by that use. • Consumable – one that can be created (produced) and destroyed (consumed).
  • 7. Reusable Resources • Such as: – Processors, I/O channels, main and secondary memory, devices, and data structures such as files, databases, and semaphores • Deadlock occurs if each process holds one resource and requests the other
  • 8. Example of Reuse Deadlock • Consider two processes that compete for exclusive access to a disk file D and a tape drive T. • Deadlock occurs if each process holds one resource and requests the other.
  • 10. Example 2: Memory Request • Space is available for allocation of 200Kbytes, and the following sequence of events occur • Deadlock occurs if both processes progress to their second request P1 . . . . . . Request 80 Kbytes; Request 60 Kbytes; P2 . . . . . . Request 70 Kbytes; Request 80 Kbytes;
  • 11. Consumable Resources • Such as Interrupts, signals, messages, and information in I/O buffers • Deadlock may occur if a Receive message is blocking • May take a rare combination of events to cause deadlock
  • 12. Example of Deadlock • Consider a pair of processes, in which each process attempts to receive a message from the other process and then send a message to the other process
  • 13. Resource Allocation Graphs • Directed graph that depicts a state of the system of resources and processes
  • 14. Conditions for possible Deadlock • Mutual exclusion – Only one process may use a resource at a time • Hold-and-wait – A process may hold allocated resources while awaiting assignment of others • No pre-emption – No resource can be forcibly removed form a process holding it
  • 15. Actual Deadlock Requires … All previous 3 conditions plus: • Circular wait – A closed chain of processes exists, such that each process holds at least one resource needed by the next process in the chain
  • 18. Dealing with Deadlock • Three general approaches exist for dealing with deadlock. – Prevent deadlock – Avoid deadlock – Detect Deadlock

Editor's Notes

  1. A set of processes is deadlocked when each process in the set is blocked awaiting an event that can only be triggered by another blocked process in the settypically processes are waiting the freeing up of some requested resource. Deadlock is permanent because none of the events is ever triggered.Unlike other problems in concurrent process management, there is no efficient solution in the general case.
  2. Animated SlideClick 1 Cars approach intersectionThen Cars announce their resource needsAll deadlocks involve conflicting needs for resources by two or more processes. A common example is the traffic deadlock. The typical rule of the road in the United States is that a car at a four-way stop should defer to a car immediately to its right.This rule works if there are only two or three cars at the intersection.If all four cars arrive at about the same time, each will refrain from entering the intersection, this causes a potential deadlock.The deadlock is only potential, not actual, because the necessary resources are available for any of the cars to proceed. If one car eventually does proceed, it can do so.
  3. Animated SlideClick 1 Cars move to deadlockThen Cars announce their resource needBut if all four cars ignore the rules and proceed (cautiously) into the intersection at the same time, then each car seizes one resource (one quadrant) but cannot proceed because the required second resource has already been seized by another car.This is an actual deadlock.
  4. If the amount of memory to be requested is not known ahead of time, it is difficult to deal with this type of deadlock by means of system design constraints. The best way to deal with this particular problem is, in effect, to eliminate the possibility by using virtual memory, which is discussed later (ch 8)
  5. Deadlock occurs if the Receive is blocking (i.e., the receiving process is blocked until the message is received). A design error is the cause of the deadlock. Such errors may be quite subtle and difficult to detect. Furthermore, it may take a rare combination of events to cause the deadlock; thus a program could be in use for a considerable period of time, even years, before the deadlock actually occurs.
  6. A graph edge directed from a process to a resource indicates a resource that has been requested by the process but not yet granted.Within a resource node, a dot is shown for each instance of that resource.A graph edge directed from a reusable resource node dot to a process indicates a request that has been granted
  7. All three must be present for deadlock to occur.
  8. This is actually a potential consequence of the first three.Given that the first three conditions exist, a sequence of events may occur that lead to an unresolvable circular wait. The unresolvable circular wait is in fact the definition of deadlock.The circular wait listed as condition 4 is unresolvable because the first three conditions hold.Thus, the four conditions, taken together, constitute necessary and sufficient conditions for deadlock.
  9. Three general approaches exist for dealing with deadlock.prevent deadlock adopt a policy that eliminates one of the conditions (conditions 1 through 4). avoid deadlock by making the appropriate dynamic choices based on the current state of resource allocation.detect the presence of deadlock (conditions 1 through 4 hold) and take action to recover.We discuss each of these approaches in turn.