2.3 Deadlock
Definition
• A situation that occurs when two programs or devices
are each waiting for a response from the other before
continuing.
• In operating systems, a situation in which two or
more processes are prevented from continuing while
each waits for resources to be freed by the
continuation of the other
• A process requests resources; if the resources are
not available at that time, the process enters a
waiting state. Sometimes, a waiting process is never
again able to change state, because the resources it
has requested are held by other waiting processes.
This situation is called a deadlock
95 51
2.3 Deadlock
Resource Deadlock
• This system is deadlocked because each process holds
a resource being requested by the other process and
neither process is willing to release the resource it
holds
96 52
2.3 Deadlock
Deadlock Conditions
4 Types of Deadlock
1. Mutual exclusion :
only one process at a
time can use a resource
Process A
Process B
t0 t3 t6
2. Hold and wait : a process holding at least one resource
while waiting for another resources.
Holds Holds
Currently I’m Currently I’m using
using a printer a scanner
Process B
Process A
53
97
2.3 Deadlock
Deadlock Conditions
3. No preemption : a process hold a resource for a long
time. Resource can be released only voluntarily by the
process holding it, after that process has completed its
task
Yes! I’m
conquered
this
printer!
Process A
Process B
I need to --wait-- --wait-- --wait-- --wait-- --wait-- --wait-- --wait-- --wait----wait-- --wait-- --wait-- -- t200
wait for a t0 wait--
long time!
98 54
2.3 Deadlock
Deadlock Conditions
4. Circular wait : processes are waiting for resources held
by other processes, which are waiting for other resources
Waiting for
Process A Process B
Waiting for Waiting for
Process D Process C
Waiting for
99 55
2.3 Deadlock
Deadlock Solutions
3 Various Of Deadlock Solutions
a. Prevention and avoidance of deadlock
Ensure deadlock does not happen
Use information about resource requests to
dynamically avoid unsafe situations
b. Allow deadlock, detect deadlock and recover
deadlock
Allow deadlocks, but detect when occur
Recover and continue
c. Ignore deadlock
100 56