What is a deadlock?
A deadlock occurs when two or more processes are waiting for each other to release resources they need to continue. This results in a situation where none of the processes can proceed, and they end up waiting indefinitely.
🔹 Coffman Conditions
The Coffman conditions, named after Edward G. Coffman, Jr., who first described them in 1971, outline four necessary conditions that must all be present for a deadlock to occur:
- Mutual Exclusion: Resources cannot be shared simultaneously
- Hold and Wait: Processes hold resources while waiting for others
- No Preemption: Resources cannot be forcibly taken away
- Circular Wait: A circular chain of processes, each waiting for a resource held by the next
🔹 Deadlock Prevention
- Resource ordering: Require processes to request resources in a specific order
- Timeouts: Set time limits for resource usage to prevent indefinite holds
- Banker's Algorithm: A method that checks if granting a resource request would lead to a safe state
🔹 Deadlock Recovery
- Selecting a victim: Choose one or more processes to terminate or roll back
- Rollback: Undo the actions of the selected process(es) to free up resources
Have you encountered any challenging deadlock situations? How did you resolve them?
cr. Sahn Lam
