Chapter 03
Chapter 03
Deadlocks
3.1. Resource
3.2. Introduction to deadlocks
3.3. The ostrich algorithm
3.4. Deadlock detection and
recovery
3.5. Deadlock avoidance
3.6. Deadlock prevention
3.7. Other issues
1
Resources
2
Resources (1)
• Formal definition :
A set of processes is deadlocked if each process in the set
is waiting for an event that only another process in the set
can cause
• Usually the event is release of a currently held
resource
• None of the processes can …
– run
– release resources
– be awakened
5
Four Conditions for
Deadlock
8
Deadlock Modeling (4)
A B C
16
Deadlock Avoidance
Resource Trajectories
• Problems
– may not know required resources at start of run
– also ties up resources other processes could be
using
• Variation:
– process must give up all resources
– then request all immediately needed
23
Attacking the No Preemption
Condition
24
Attacking the Circular Wait Condition (1)
(a) (b)
25
Attacking the Circular Wait Condition (1)
• Phase One
– process tries to lock all records it needs, one at
a time
– if needed record found locked, start over
– (no real work done in phase one)
• If phase one succeeds, it starts second
phase,
– performing updates
– releasing locks
• Note similarity to requesting all resources
at once
• Algorithm works where programmer can
arrange 27
Nonresource Deadlocks
28
Starvation
• Algorithm to allocate a resource
– may be to give to shortest job first
• Solution: 29