The process is said to be in a deadlock state when the resource required by it is in use with second process and is waiting for other resource. In a deadlock situation no process is able to execute and the system gets hanged as every process is waiting for the resource which is being held by the other process. For example the deadlock situation can be well explained as suppose there are three processes- P0, P1 and P2 and three resources R1, R2 and R3. Let the resource R1 is held by process P1 and requests for resource R2, resource R2 is held by the process P1 and requests for the resource R3, the resource R3 by the process P0 and requests for the resource R1, then in this case the deadlock situation will arise and none of the process will be able to complete its task and will lead to halt in the working of the computer system.
For the deadlock situation there are certain conditions that must occur simultaneously. The conditions that must occur are:-
1. Mutual Exclusion: - One process uses the resource one at a time.
2. Hold and Wait: - Process needs to use or either hold one of the resource and should be waiting for the other resource being hold or used by another process.
3. No Pre-emption: - the process should release the resource voluntarily when it has completed the task over that resource.
4. Circular wait: - there should be the circular chain of the processes where one process is holding the resource which is being required by another process.
Resource Allocation graph
The deadlock situation can be presented using the graph system. The vertices of the graph circular in shape represent the processes and the squares of the graph represent the resources which can hold multiple instances of the resource and is indicated by dots.
Process represented as
Resources represented as
R0
If the arrow head of the edge is from process to resource then it means that the process is requesting for the resource and if the arrow head is from the resource to process then it means that the instance of the resource is held by the process.
There are various strategies to avoid the deadlock situation like either not do anything, avoidance, prevention and detection and recovery. The strategy not to do anything does not solve the problem at all. The other three strategies are very useful and different ways to avoid deadlock.
Tags:
Deadlock Situation
Processes
Computer System
Graph