Deadlock

Deadlock is not bad luck and it is not a race you lose occasionally. It is a cycle: each program holds something the next one needs, all the way round. With five philosophers and five forks the whole world is small enough to count rather than watch — every order in which they can reach for forks is enumerable, the ones that hang can be listed exactly, and the fix can be checked against all of them instead of demonstrated on one.

Five philosophers, five forks, and the order that hangs

1 Five philosophers, five forks, and each one reaching left then right

Five philosophers around a table, one fork between each pair. To eat you need both.

Aristotlefork 0 held · fork 1 wanted
Boethiusfork 1 held · fork 2 wanted
Cicerofork 2 held · fork 3 wanted
Diogenesfork 3 held · fork 4 wanted
Epictetusfork 4 held · fork 0 wanted

2 The orders that finish, and the orders where every philosopher holds one fork

One round of reaching, everybody taking a single fork before anybody takes a second. This is one specific order, not an accident.

philosopherholdswaiting forheld by
Aristotlefork 0fork 1Boethius
Boethiusfork 1fork 2Cicero
Cicerofork 2fork 3Diogenes
Diogenesfork 3fork 4Epictetus
Epictetusfork 4fork 0Aristotle

Every one of them holds a fork and waits for the next: Aristotle → Boethius → Cicero → Diogenes → Epictetus → Aristotle. Nothing can move, and nothing is broken.

3 All four of Coffman's conditions, checked against the state that hung

Coffman’s four conditions, read off the state above rather than recited. Deadlock needs all four; removing any one is enough.

conditionholds?why
mutual exclusionyesa fork is held by one philosopher or none; that is what a fork is
hold and waityes5 are holding one fork and waiting for another
no pre-emptionyesnothing takes a fork back; a philosopher puts one down only after eating
circular waityesa cycle: Aristotle waits for Boethius waits for Cicero waits for Diogenes waits for Epictetus

4 Number the forks and take the lower first: every order finishes, counted

Every opening order there is, counted both ways. Not a sample.

opening orders
3,125
hang, reaching left first
278 (8.9 per cent)
hang, taking the lower fork first
0

Neither rare nor certain, which is exactly what makes deadlock hard to find by running the program: 278 of 3125 openings hang, and the other 2847 finish and tell you nothing is wrong.

These ran in this browser when the page loaded. Each claim, whether it held, and the number behind it.

Each claim, whether it held, and the values behind it
claimheldmeasured
taking left then right, one round each, deadlocks all 5yesa cycle of 5: every philosopher waits for the next
of all 3125 opening interleavings, 278 deadlockyesit is neither rare nor certain, which is what makes it hard to catch by running it
numbering the forks and taking the lower first: 0 of 3125 deadlockyesevery opening finishes
the ordered version breaks exactly one of Coffman's four conditionsyescircular wait

What is real here, and what is not

This counts openings, not every possible schedule

The enumeration walks every way the first five grabs can be interleaved — 3,125 of them — and then lets the system run freely to a fixed point. That is not the same as every possible schedule of the whole meal, which is unbounded. What it does establish is exactly what the page claims: of those openings, 278 reach a state from which nothing can proceed, and none do once the forks are numbered.

The fix is a total order on the resource, not politeness

Taking the lower-numbered fork first works because it makes a cycle impossible: in any set of philosophers each holding one fork, one of them holds the highest-numbered fork in the set and is therefore waiting for nothing in it. Timeouts, backoff and retrying are not this. They make deadlock rarer and leave it possible, and this page does not model them.

Nothing here is concurrent

Five philosophers is a loop over five entries in an array, and the interleaving is a list this page walks. There is no thread, no lock and no scheduler, so the page cannot show you a race — only why the counting rule is the right counting rule. A real system adds the part where you cannot see the state at all, which is most of what makes this hard.

The problem is Dijkstra's, the name is Hoare's, and the first citation here was wrong

This page cited EWD123, Cooperating Sequential Processes, as where the dining philosophers first appear. They do not appear in it: the archived copy in this repository is 109,280 bytes and contains the words philosopher, dining, quintuple and fork exactly nought times. What it does contain is the semaphore and the deadly embrace, which is why it is still cited. Dijkstra gives the history himself in EWD1000: EWD123 “was written in 1965 and served as lecture notes for my course in the fall semester of that year. (The problem of The Dining Quintuple —later dubbed ‘The Dining Philosophers’ by Tony Hoare— was the examination problem at the end of that semester.)” So the year is right, the document was not, and the familiar name is Hoare's rather than Dijkstra's. EWD198 works the problem under Dijkstra's name for it. An outside reader caught this on the live page on 2026-08-22. No gate here could have: every one of them checks that a cited document was fetched, not that it says what the page says it says.

Numbering the forks fixes deadlock and does nothing about starvation

A total order on the resource guarantees the group as a whole keeps moving. It guarantees nothing to any particular philosopher: with the right repeated schedule one of them can wait while the others eat, forever, and every check on this page stays green throughout because nothing is deadlocked. The two problems get confused constantly and they have different fixes — starvation wants fairness, a queue or a ticket, which this model does not have. Dijkstra's own solution used a semaphore per philosopher for exactly that reason.

Sources