Deadlock I
Tom Kelliher, CS 311
Mar. 30, 2012
Finish reading Chapter 7.
Classic synchronization problems.
- System model.
- Deadlock examples.
- Necessary conditions for deadlock.
- Resource allocation graphs.
- Dealing with deadlocks.
- Deadlock prevention.
Deadlock II.
- Processes competing for resources. Process model:
while (1)
{
request some resources;
compute;
release some resources;
}
- Resource: anything a process may block on. Examples:
- Semaphore.
- Device (disk read/write, printer, etc.)
- Memory.
- CPU.
- File.
Two types of resources:
- Serially reusable resources: printer, tape drive, CPU, etc.
- Consumable resources: semaphores, messages, etc.
semaphore A(0), B(0);
process1()
{
A.wait();
B.signal();
}
process2()
{
B.wait();
A.signal();
}
Process 1 is waiting for process 2 is waiting for process 1...
System has five tape drives.
Process |
Allocated |
Request |
P1 |
2 |
2 |
P2 |
2 |
3 |
P3 |
1 |
1 |
Resource allocation graph.
- Mutual exclusion -- A resource is not sharable.
- Hold and wait -- A process is allowed to hold a resource while it's
waiting for other resources.
- No preemption -- A process cannot be forced to give up a resource.
- Circular wait -- P1 is blocked because of P2; P2 is blocked because
of P3; ...; Pn is blocked because of P1.
Why aren't these sufficient conditions?
How does deadlock differ from starvation?
Pretty simple:
- Vertices:
- Processes.
- Collections of resources of same type.
- Edges:
- Ignorance. More common than you'd think.
- Detection and recovery.
- Prevention -- Prevent one of the four necessary conditions.
- Avoidance -- Manage resources so that a deadlock never occurs:
Removal of one of the four necessary conditions.
- Share the resource.
- Example?
- Limitations?
- A process must release all resources before requesting more.
- Example?
- Limitations? (Request everything at once or wait a lot.)
- Kernel forcibly reclaims resources.
- Example?
- Limitations?
- Impose a total order on all resources.
- Resource i may only be requested if process holds no resource
j with .
- Example?
- Limitations:
- Determining the order.
- How does an ``out of order'' process proceed?
- Works for specific resources.
- No one mechanism is generally applicable.
Thomas P. Kelliher
2012-03-29
Tom Kelliher