2. CONTENTS
What is Deadlock?
Dead lock
Characterization
Approaches of Dead Lock
•Dead ock
Prevention
•Deadlock Detection
•Deadlock
Avoidance
10/6/2021
2 Dr.M.Karthika AP/IT/MTNC
3. What is Deadlock?
Deadlock is a situation that occurs in OS.
Deadlocks are a set of blocked processes each
holding a resource and waiting to acquire a resource
held by another process.
Deadlock is a common problem in multi-processing
where several processes share a specific type of
mutually exclusive resource known as a soft lock or
software.
10/6/2021
3 Dr.M.Karthika AP/IT/MTNC
4. Every process needs some resources to complete
its execution. However, the resource is granted in a
sequential order.
The process requests for some resource.
OS grant the resource if it is available otherwise let the process
waits.
The process uses it and release on the completion.
10/6/2021
4 Dr.M.Karthika AP/IT/MTNC
5. Example
In the below diagram, Process 1 is holding Resource 1 and waiting for
resource 2 which is acquired by process 2, and process 2 is waiting
for resource 1.
10/6/2021
5 Dr.M.Karthika AP/IT/MTNC
6. Deadlock Characterization
( four Coffman conditions )
1. Mutual Exclusion
A resource can only be shared in mutually exclusive
manner. It implies, if two process cannot use the same
resource at the same time.
2. Hold and Wait
A process waits for some resources while holding
another resource at the same time.
10/6/2021
6 Dr.M.Karthika AP/IT/MTNC
7. 3. No preemption
The process which once scheduled will be executed till
the completion. No other process can be scheduled by
the scheduler meanwhile.
4. Circular Wait
All the processes must be waiting for the resources in a
cyclic manner so that the last process is waiting for the
resource which is being held by the first process.
10/6/2021
7 Dr.M.Karthika AP/IT/MTNC
8. There are three approaches to deal with deadlocks.
1. Deadlock Prevention
2. Deadlock avoidance
3. Deadlock detection
10/6/2021
8 Dr.M.Karthika AP/IT/MTNC
9. Deadlock Prevention
The strategy of deadlock prevention is to design the
system in such a way that the possibility of deadlock
is excluded.
Indirect method prevent the occurrence of one of three
necessary condition of deadlock i.e., mutual exclusion,
no pre-emption and hold and wait.
Direct method prevent the occurrence of circular wait.
10/6/2021
9 Dr.M.Karthika AP/IT/MTNC
11. Deadlock Detection
Deadlock can be detected by the resource scheduler
as it keeps track of all the resources that are
allocated to different processes.
After a deadlock is detected, it can be handed using
the given methods
All the processes that are involved in the deadlock are
terminated. This approach is not that useful as all the
progress made by the processes is destroyed.
Resources can be preempted from some processes
and given to others until the deadlock situation is
resolved. 10/6/2021
11 Dr.M.Karthika AP/IT/MTNC
12. Deadlock Avoidance
It is better to avoid a deadlock rather than take
measures after the deadlock has occurred.
The wait for graph can be used for deadlock
avoidance. This is however only useful for smaller
databases as it can get quite complex in larger
databases.
10/6/2021
12 Dr.M.Karthika AP/IT/MTNC
13. A decision is made dynamically whether the current
resource allocation request will, if granted, potentially
lead to deadlock.
It requires the knowledge of future process requests.
Two techniques to avoid deadlock :
Process initiation denial
Resource allocation denial
10/6/2021
13 Dr.M.Karthika AP/IT/MTNC
14. Advantages :
Not necessary to pre-empt and rollback processes
Less restrictive than deadlock prevention
Disadvantages :
Future resource requirements must be known in
advance
Processes can be blocked for long periods
Exists fixed number of resources for allocation
10/6/2021
14 Dr.M.Karthika AP/IT/MTNC