🍝
A tasty intro to concurrency

Why can't they all just eat?

Five hungry philosophers, five forks, and one little rule that can freeze the whole table forever. Meet locks, mutexes and deadlock — the fun way.

no setup · click things · watch what happens

The 5-year-old's guide to deadlock

Six tiny ideas. Then you go play with them.

🍴

A fork is a lock

Only one person can hold a fork at a time. If you have it, your neighbour has to wait. That's exactly what a lock does in code: it lets just one task use something at once.

A lock (or mutex — "mutual exclusion") guarantees only one thread enters a critical section at a time.

🔒

Locking & unlocking

Picking up a fork = locking. Putting it down = unlocking. While you hold it, nobody else can. When you're done eating, you let go so someone else can grab it.

lock() acquires; unlock() releases. Forgetting to unlock starves everyone else.

💥

Deadlock

If everyone grabs their left fork at the same time, every philosopher is holding one fork and waiting for the other — which their neighbour is holding. Nobody will ever let go. Everyone is stuck forever. That's a deadlock.

Deadlock needs all four at once: mutual exclusion, hold-and-wait, no preemption, and a circular wait. Break any one and you're safe.

🔢

Fix #1 — Fork order

Number the forks. Make everyone grab the smaller number first. Now the circle can't close — someone always gets both forks and eats.

A resource hierarchy breaks the circular-wait condition.

🤵

Fix #2 — The waiter

A waiter only lets you pick up forks if both are free. So you never get stuck holding just one.

An arbitrator (a single mutex) makes the two pickups atomic, killing hold-and-wait.

🪑

Fix #3 — Limited seats

Leave one chair empty. With someone always sitting out, there's a gap in the circle, so it can't lock up.

A counting semaphore of N−1 caps concurrent diners and breaks the cycle.

The game, in 3 steps 👇

  1. Cause it. On the Naïve rule, click each philosopher to hand them a fork. Give everyone their first fork, then reach for the second
  2. Feel it. 💥 The table locks solid — every fork held, everyone waiting in a circle, nobody can eat. You built a deadlock with your own hands.
  3. Fix it. ✅ Switch to Fork Order, The Waiter, or Limited Seats and try the exact same thing. It won't jam — and the game tells you which rule broke which condition.
① the problem Jam the table — click each philosopher to grab a fork. fixes proven · 0/3
Welcome to dinner!

👆 Click a philosopher to pick up a fork

  • thinking
  • hungry
  • holding a fork, waiting
  • eating 🍝
  • stuck (deadlock)

Why it jams — a deadlock needs all four

All four can happen here, so this table can deadlock.