Deadlocks & Coffman Conditions
- Mutex & Semaphore
- Process Synchronization basics
Introduction
Deadlock ek aisi situation hai computer system me, jahan do ya do se zyada processes block ho jate hain kyunki har ek process us resource ko hold karke baitha hai jo doosre ko chahiye, aur wo kisi aur resource ke release hone ka wait kar raha hai. Yeh simple infinite loop ki tarah hai jisse system freeze ho jata hai.
Real-Life Analogy
💡 Narrow Bridge Crossing
Single lane bridge deadlock
| Concept Term | Real-life Analogy Mapping |
|---|---|
| Resource | Narrow Single-lane Bridge |
| Process A | Car coming from Left side |
| Process B | Car coming from Right side |
| Deadlock State | Dono cars bridge ke center me aake face-to-face ruk gayi hain, koi aage-piche nahi ho raha |
Detailed Concept Explanation
Deadlock lagne ke liye 4 conditions ka EKSATH (simultaneously) satisfy hona zaroori hai. Inhe Coffman Conditions kehte hain: 1. **Mutual Exclusion**: Kam se kam ek resource non-shareable hona chahiye (ek time pe ek hi process use kar sake). 2. **Hold and Wait**: Process ek resource ko hold karke doosre resource ka request/wait kar raha ho. 3. **No Preemption**: Kisi process se uska resource zabardasti nahi chhina ja sakta. Wo khud hi free karega. 4. **Circular Wait**: Processes ki aisi cycle ban jaye jahan P0, P1 ka wait kar raha hai, P1, P2 ka, and Pn, P0 ka wait kar raha hai.
Visual Diagram
- Agar in 4 conditions me se ek bhi condition ko invalid kar dein, toh deadlock kabhi nahi lagega.
- Resource Allocation Graph (RAG) me cycle hona Single Instance resource case me deadlock confirm karta hai.
- Deadlock Prevention methods target break of any of the 4 conditions.
M-N-H-C (Mere Naal Hasi Chalo)
Mutual exclusion, No preemption, Hold & wait, Circular wait
Practice Mini Quiz
Revision Summary (One-Page Notes)
- •Deadlock is a state of mutual block.
- •Coffman conditions are Mutual Exclusion, Hold & Wait, No Preemption, and Circular Wait.
- •Strategies include Prevention, Avoidance (Banker's Algorithm), Detection, and Recovery.