Home▸Computer Science▸Dining Philosophers Deadlock Simulator (2D)

Dining Philosophers Deadlock Simulator (2D)

A top-down canvas table where naive, resource-ordering and waiter-arbitrator locking strategies drive the same fork-acquisition state machine as the 3D version, so you can watch a circular wait freeze the whole table.

Computer Science2DModerate60 FPS📱 Mobile-adapted⇄ 3D version
2d-dining-philosophers-deadlock-lab ↗ Open standalone

This 2D companion drives the exact same fork-acquisition state machine as the 3D round table through a plain top-down canvas: pick naive, resource-ordering or waiter-arbitrator locking, adjust philosopher count and simulation speed, and watch seat colour track each philosopher's state (thinking/waiting/eating/deadlocked) while fork colour and hand-lines show who holds what, ending in a full-table deadlock banner whenever a circular wait forms under the naive strategy.

⚙ Under the hood

2D top-down dining-philosophers lab with naive, resource-ordering and waiter-arbitrator locking strategies driving a live fork state machine and deadlock detector, matching the 3D version's mechanics.

dining philosophersdeadlockconcurrencyresource allocationstarvationoperating systems

2D · HTML5 Canvas 2D · 60 FPS target · runs fully client-side, no install

Why does the naive strategy deadlock?

If every philosopher grabs their left fork first and then waits for their right, and all get hungry at once, each holds one fork while waiting on a neighbour who holds the fork they need — a circular wait that never resolves.

How does resource ordering prevent deadlock?

Every philosopher must pick up the lower-numbered fork first. The highest-numbered philosopher then reaches for a different fork first than everyone else, which breaks the circular chain and makes deadlock structurally impossible.

What does the waiter / arbitrator strategy do?

A central arbitrator only lets up to N−1 philosophers attempt to pick up forks at the same time, guaranteeing that at least one philosopher can always finish eating and release forks for the rest.

What did you find?

Add reproduction steps (optional)