DeadLocks
A Deadlock is a situation where each of the computer processes waits for a resource which is being assigned to some other process. In this situation, none of the process gets executed since the resource it needs is held by some other process which is also waiting for some other resource to be released.
Example for deadlock:
There are following 4 necessary conditions for the occurrence of deadlock-
- Mutual Exclusion
- Hold and Wait
- No preemption
- Circular wait
- There must exist at least one resource in the system which can be used by only one process at a time.
- If there exists no such resource, then deadlock will never occur.
- Printer is an example of a resource that can be used by only one process at a time
- There must exist a process which holds some resource and waits for another resource held by some other process.
- Once the resource has been allocated to the process, it can not be preempted.
- It means resource can not be snatched forcefully from one process and given to the other process.
- The process must release the resource voluntarily by itself.
- All the processes must wait for the resource in a cyclic manner where the last process waits for the resource held by the first process.
- All these 4 conditions must hold simultaneously for the occurrence of deadlock.
- If any of these conditions fail, then the system can be ensured deadlock free.
- Deadlock Prevention
- Deadlock Avoidance
- Deadlock Detection and Recovery
- Deadlock Ignorance
Maximum Number Of Units That Ensures Deadlock-
Maximum number of units of resource R that ensures deadlock
= (x1-1) + (x2-1) + (x3-1) + …. + (xn-1)
= ( x1 + x2 + x3 + …. + xn ) – n
= ∑xi – n
= Sum of max needs of all n processes – n
Minimum Number Of Units That Ensures No Deadlock-
Minimum number of units of resource R that ensures no deadlock
= One more than maximum number of units of resource R that ensures deadlock
= (∑xi – n) + 1
Problems on no. of resources required
1Q. A system is having 3 user processes each requiring 2 units of resource R. The minimum number of units of R such that no deadlock will occur-
Ans: 4
2Q. A system is having 8 user processes each requiring 3 units of resource R. The minimum number of units of R such that no deadlock will occur _____.
Ans: 17
Problems on no. of processes required
3Q. If there are 6 units of resource R in the system and each process in the system requires 3 units of resource R, then how many processes can be present at maximum so that no deadlock will occur?
Ans:
- Process P1 holds 2 units of resource R
- Process P2 holds 2 units of resource R
- Process P3 holds 2 units of resource R
Therefore,
- Minimum number of processes that ensures deadlock = 3
- Maximum number of processes that ensures no deadlock = 3 – 1 = 2
- Process P1 holds 3 units of resource R
- Process P2 holds 3 units of resource R
- Process P3 holds 3 units of resource R and so on.
- Process P33 holds 3 units of resource R
- Process P34 holds 1 unit of resource R
Thus,
- Minimum number of processes that ensures deadlock = 34
- Maximum number of processes that ensures no deadlock = 34 – 1 = 33