Master Deadlock Concepts for Interviews & Exams
Both cars are stuck forever!
Deadlock: A situation where two or more processes are permanently blocked, each waiting for resources held by the other processes.
Process β Resource (Request), Resource β Process (Allocation)
ALL FOUR must be present simultaneously for deadlock to occur!
Only ONE process can use a resource at a time
Process holds resources while waiting for more
Resources cannot be forcibly taken away
Processes form a circular chain of waiting
Strategy: Prevent at least one of the four conditions
Strategy: Use algorithms to avoid unsafe states
Strategy: Allow deadlock, then detect and recover
Strategy: Pretend deadlocks don't happen
| Condition | Prevention Method | Pros | Cons | Example |
|---|---|---|---|---|
| Mutual Exclusion | Make resources shareable whenever possible | Simple to apply for some resources (e.g., read-only files) | Not possible for resources that must be used exclusively (e.g., printer) | Allow multiple processes to read the same file in parallel |
| Hold & Wait | Require processes to request all resources at once before execution | Eliminates partial allocation β prevents circular dependency | May cause resource underutilization and starvation if a process holds resources it doesnβt need yet | A program must request CPU, memory, and disk all at once before starting |
| No Preemption | If a process holding some resources requests others and canβt get them, release its current resources | Breaks potential deadlock cycle by freeing resources | Frequent preemptions can cause livelock (processes repeatedly release and reacquire resources without progress) | If a process holding CPU and requesting I/O canβt get it, CPU is preempted and given to another |
| Circular Wait | Impose a linear ordering on resource types and require processes to request in increasing order | Most practical and widely used method | Requires predefined ordering of all resources, which may not always be flexible | A process must request printer (R1) before scanner (R2); cannot request in reverse |
Selection Criteria: Priority, computation time, resources held
| Method | Resource Utilization | System Throughput | Implementation | Real-world Usage |
|---|---|---|---|---|
| Prevention | Low | Low | Simple | Limited |
| Avoidance | Medium | Medium | Complex | Specialized systems |
| Detection | High | Medium | Medium | Database systems |
| Ignorance | High | High | None | Most OS (Windows, Linux) |
A: Deadlock cannot occur. This is the basis of deadlock prevention - eliminate at least one necessary condition.
A: Prevention methods reduce system efficiency and resource utilization. Deadlocks are rare in practice, so most systems use the "ignore" approach.
A: Deadlock is mutual waiting (circular), while starvation is indefinite waiting due to resource allocation policies.
A: It simulates resource allocation and checks if a safe sequence exists. If not, it denies the request.