Operating - System Deadlock
Operating - System Deadlock
Operating - System Deadlock
Deadlocks
1
Resources
3
Resources (2)
• 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
11
Detection with One Resource of Each Type (1)
12
Recovery from Deadlock (1)
13
Recovery from Deadlock (2)
14
Deadlock Avoidance
Resource Trajectories
16
Attacking the Hold and Wait Condition
• 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
17
Attacking the No Preemption Condition
18
Attacking the Circular Wait Condition (1)
(a) (b)
19
Attacking the Circular Wait Condition (1)
20
Other Issues
Two-Phase Locking
• 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
– program can be stopped, restarted
21
Nonresource Deadlocks
22
Starvation
• Algorithm to allocate a resource
– may be to give to shortest job first
• Solution:
– First-come, first-serve policy
23