What is Deadlock?
A Deadlock is a situation in which two or more processes are waitingfor resources held by each other, and none of them can proceed.
Necessary Conditions of Deadlock
- Mutual Exclusion
- Hold and Wait
- No Preemption
- Circular Wait
Example of Deadlock
Process P1 holds Resource A and waits for Resource B. Process P2 holds Resource B and waits for Resource A. Both processes wait forever.
Methods to Handle Deadlock
- Deadlock Prevention
- Deadlock Avoidance
- Deadlock Detection
- Deadlock Recovery
Prevention Techniques
- Allocate all resources at once
- Allow resource preemption
- Avoid circular waiting
- Use proper scheduling