Deadlock
Deadlock
1
Deadlock
• Situation when resources are allocated to active processes, so
that no further processing is possible.
• Deadlock occurs when
resources ˂˂ processes
• A process in a multi-programming system is said to be in a state
of deadlock if it is waiting for a particular event that will not
occur.
2
Deadlock
• Consider two processes P1 and P2 and two resources R1 and
R2.
• Suppose P1 holds R1 and P2 holds R2. In the mean time P1
needs R2 and P2 needs R1 but no process can get extra
resources because they are already provided, so they are waiting
for other resources and the deadlock situation occurs.
P1 P2
Wait for
Wait for
holds holds
R1 R2
3
Conditions for deadlock occurrence
• Four conditions
Mutually exclusive
Wait for
Non pre-emptive
Circular chain
• Mutually exclusive
• Every process can be activated at any time and all active
processes have the same rights for sharing resources i.e.,
every process can request for every resources.
4
Conditions for deadlock occurrence
• Wait for
• When there is an infinite wait for a resource, it can lead to
deadlock situation.
P1 P2
holds holds
Request for
R1 R2
5
Conditions for deadlock occurrence
• Non pre-emptive
• If processes are pre-emptive deadlock can’t occurs.
• Circular chain
• If there exists a set of waiting processes {P0, P1, P2, …, Pn},
such that P0 is waiting for resource which is held by P1, and
P1 is waiting for resource which is held by P2, and Pn-1 is
waiting for resource which is held by Pn and Pn is waiting
for resources which is held by P0. This situation is called
circular chain (wait) which causes deadlock.
• When circular chain occurs, it means deadlock condition
occurs.
6
Conditions for deadlock occurrence
• Let there are three active processes P1, P2 and P3 and there are
three resources available R1, R2, and R3.
R3 R1
P3 P2
8
Deadlock prevention
• Most frequently used method.
• Various strategies for denying various conditions for deadlock
occurrence have been suggested.
1. All the resources must be allocated in advance and process
can’t be started if all resources are not available.
(denying the wait-for condition)
9
Deadlock prevention
P1 P2 P3
R1 R2 R3 R2 R4 R5 R3 R6 R7
10
Deadlock prevention
2. If the request is denied, the process must release its original
resources and if necessary, request again with additional
resources.
(denying the wait-for and non pre-emption condition)
11
Deadlock avoidance
The side effects of deadlock prevention are
• Low device utilization and
• Reduced system efficiency
12
Banker’s algorithm
“All available resources should be allocated in a manner that it can
guarantee safe state.”
13
Banker’s algorithm
Example of safe state:
Available storage resources = 12
Active processes = 3
Active processes Max required Currently
resources allocated
resources
P1 10 4
P2 6 4
P3 4 2
15
Banker’s algorithm
Example of un-safe state:
16
Starvation
• Situation in which resources will always be pre-empted from
same process. As a result this process is never completed its task
and starvation situation occurs.
17