Deadlock Management
Original Scanned PDF – View Notes
Introduction
- Deadlock is a situation when set of processes are blocked because each process is holding resource and waiting for another resource.
- Deadlock occur when two or more processes are unable to proceed because they are waiting for each other to release resource.
- This situation leads unable to execute process further.
Example of Deadlock
Suppose there are two processes P1 and P2 and two resources R1 and R2.
Each process needs to access to both resources to complete it execution.
The Sequence of Events Is as Follow:
- P1 request R1 and gets it.
- P2 request R2 and gets it.
- P1 request R2 but it is held by P2, so P1 waits.
- P2 request R1 but it is held by P1, so P2 waits.
Now, neither P1 nor P2 can proceed further as they are waiting for each other to release the resources they need. This situation is called deadlock.
Process are stuck, and system in unresponsive until deadlock is resolved.
Necessary Condition for Deadlock
Deadlock can arise if following conditions hold simultaneously.
- Mutual Exclusion
- Hold and Wait
- No Preemption
- Circular Wait
1. Mutual Exclusion
- There should be a resource that can only be held by one process at a time.
- In diagram below, there is a single instance of Resource 1 and it is held by process 1 only.
2. Hold and Wait
- A process can hold multiple resource & still request more resources from other process which are holding them.
- In the diagram below, process-2 holds Resource-2 and Resource-3 and is requesting the Resource-1 which is held by process-1.
3. No Preemption
- A resource can not be preempted from a process by force.
- A process can only release a resource voluntarily.
- In fig below, process-2 can not preempt Resource-1 from process-1.
- It will only be released when process-1 release it voluntarily after it execution is complete.
4. Circular Wait
A process is waiting for the resource held by the second process, which is waiting for the resource held by third process and so on, till the last process is waiting for a resource held by the first process. This forms a circular wait.
For example: process-1 is allocated Resource-2 and it is requesting Resource-1. Similarly, process-2 is allocated Resource-1 and it is requesting Resource-2. This form a circular wait loop.
Method of Handling Deadlock
There are 3 technique to handle deadlock:
- Deadlock prevention
- Deadlock detection and recovery
- Deadlock avoidance
1. Deadlock Prevention
- It is very important to prevent a deadlock before it can occur.
- So, system checks each transaction before it is executed to make sure it does not lead to deadlock.
- If there is even a slight chance that a transaction may lead to deadlock in the future, it is never allowed to execute.
2. Deadlock Detection and Recovery
- A deadlock can be detected by a resource scheduler as it keeps track of all resources that are allocated to different process.
- After deadlock is detected, it can be resolved using following method:
- All the process that involved in deadlock are terminated. This is not a good approach as all the progress made by the processes is destroyed.
- Resources can be preempted from some processes and given to other till the deadlock is resolved.
3. Deadlock Avoidance
- It is better way to avoid deadlock rather than measure after the deadlock has occurred.
- The wait for graph is used for deadlock avoidance.
- Suitable for smaller database as it can get quite complex in layer database.
Wait-for Graph
The supplied notes state that the wait for graph is used for deadlock avoidance and that it is suitable for smaller database because it can get quite complex in layer database.
This is the final topic written on page 9 of the supplied scan. No additional wait-for graph diagram or worked example is included in the source PDF.
Discussion
Share a helpful question, idea, or explanation with other students.