Deadlocks
Deadlocks
Deadlocks
Deadlocks
6.1. Resource
6.2. Introduction to deadlocks
6.3. The ostrich algorithm
6.4. Deadlock detection and recovery
6.5. Deadlock avoidance
6.6. Deadlock prevention
6.7. Other issues
1
Resources
Examples of computer resources
printers
tape drives
tables
Resources (1)
Deadlocks occur when
processes are granted exclusive access to devices
we refer to these devices generally as resources
Preemptable resources
can be taken away from a process with no ill effects
Nonpreemptable resources
will cause the process to fail if taken away
3
Resources (2)
Introduction to Deadlocks
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
1.
2.
No preemption condition
3.
4.
1.
2.
3.
4.
prevention
(o)
(p)
(q)
10
15
16
Deadlock Avoidance
Resource Trajectories
(a)
(b)
(c)
(d)
(e)
18
(a)
(b)
(c)
(d)
(a)
(b)
(c)
Deadlock Prevention
Attacking the Mutual Exclusion 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
23
24
(a)
(b)
26
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)
Nonresource Deadlocks
Possible for two processes to deadlock
each is waiting for the other to do some task
28
Starvation
Algorithm to allocate a resource
may be to give to shortest job first
Solution:
First-come, first-serve policy
29