It is the last working day of the month in a bank's back office. Two jobs run on the same server: one prints the salary statements, the other posts the day's transfers. At four in the afternoon both jobs say "running". At five they still say "running". The CPU is idle, the disk is quiet, no log shows an error, and nothing moves. Someone restarts the server and everything is fine again, until the next month-end. Nothing crashed. Two programs are each waiting for something that only the other one can give, so they will wait for ever.
This is a deadlock, and it is one of the strangest bugs in computing because it does not look like a bug at all. There is no crash and no wrong answer, only silence. It is also a favourite of paper-setters: the four conditions, the resource-allocation graph, "does a cycle always mean deadlock?" and the ways of handling deadlock come up in BCS, bank and university papers year after year.
By the end you will explain deadlock with a picture and a real program, name Coffman's four conditions, read a resource-allocation graph, tell deadlock from starvation and livelock, and explain how deadlock is prevented, avoided, detected and recovered from. You will also watch a deadlock on a real machine, see a tool catch it, and fix it with a one-line rule.
Why it matters: Exams ask about deadlock in two ways. One-mark MCQs test a single fact or a small piece of reasoning: which algorithm avoids deadlock, which option is not a way of handling it, how many extra units resolve a given graph, why multi-threaded programs are more prone to it. Written questions ask you to explain: what deadlock is, its four necessary conditions, whether a cycle in a graph always means deadlock, whether one process alone can deadlock, how deadlock is prevented, avoided, detected and recovered from, and to draw the diagram. Every one of these ideas is taught below, together with its reason.