Picture four philosophers sitting around a table, each holding one chopstick and waiting for the one to their right. Nobody can eat, nobody will let go, and the table stays frozen forever. That story, invented by Edsger Dijkstra in 1965, is the classic image of a deadlock.
In a real operating system, the philosophers are processes and the chopsticks are resources â files, locks, memory pages, network sockets. A deadlock forms when a set of processes is stuck in a circular wait: process A holds resource 1 and waits for resource 2, process B holds resource 2 and waits for resource 1, and neither can ever proceed.
The four conditions that must all hold simultaneously for a deadlock to exist were identified by Coffman, Elphick, and Shoshani in 1971:
- Mutual exclusion â a resource can be held by at most one process at a time.
- Hold and wait â a process holding a resource can request more.
- No preemption â resources can only be released voluntarily.
- Circular wait â a cycle exists in the wait-for graph.
Remove any one condition and deadlock is impossible. But in practice the first three are often unavoidable, so the question becomes: can we detect the circular wait before it brings the system down?
Comments
Loading comments...