Dining philosophers
Step through individual fork acquisitions and inspect ownership, waiting and completed meals.
About this tool
Follow five philosophers sharing five forks. Step performs exactly one action; Start advances automatically at 0.25–4 actions/s. Both create the initial state on first use. Reset keeps your scheduling settings. Example loads an initial state, a waiting philosopher or two non-neighboring philosophers eating; the latter two choose Manual and P1 so the next step can release or acquire a resource.
P1 needs F0/F1, P2 F1/F2, P3 F2/F3, P4 F3/F4, P5 F4/F0. Each takes the lower-numbered fork first, including F0 before F4 for P5. One action makes a thinking philosopher hungry, attempts the first fork, attempts the second fork and starts eating, or releases both forks and completes one meal. A blocked attempt still counts as an action. The table shows held and requested forks, blockers and completed meals; the lines show ownership.
Round robin selects the next philosopher after each action. Manual lets you choose any philosopher. In the waiting example P1 holds F0 while P5 waits: a P1 step takes F1, the following step releases both forks. P5 can then take F0. The resource hierarchy prevents circular resource waiting, but does not guarantee fairness: repeatedly selecting a waiting philosopher cannot make its owner release a fork. This is a deterministic teaching model, not real threads or a physical-time simulation.
Changing scheduling, philosopher or pace pauses without discarding state. Pause, hiding or leaving the tool stops its single timer; missed time is never replayed. Returning, reloading or changing language restores the exact paused state, including the next philosopher, meals and raw pace input. No external computation. Background: Dijkstra and Scholten, Distributed Arbitration (EWD752). Its stronger arbitration assumptions are not a fairness guarantee for this selectable scheduler.
Fork owners are available in the expandable section below the state table. Invalid snapshots are rejected without discarding the current session. Earlier settings-only saved links are still accepted and start without a simulation. Automatic playback is never restored. The action counter stops at the largest safe JavaScript integer; Reset starts again at zero. Browser local storage and optional JSON files remain on your device.
Only input values are remembered in this browser. Calculated results and experiment histories are not saved.