Order the cooks' tools in Pak Tono's hajatan kitchen: 18 levels of mutexes, data races, deadlocks and lock ordering. 18 levels, right in the browser.
Several cooks (goroutines) work one kitchen at the same time. If two cooks change the same dish (shared data) at the same moment, the result is a mess: that is a data race. The cure is a mutex, a tool only one person can hold. A cook must hold the guarding tool before touching its dish. Set each cook's tools, then start cooking: the engine tries every order of events, and if one goes wrong, the kitchen plays that order step by step. If every order is safe, the kitchen cooks for real in rounds: each round every cook takes one step (taking a tool, cooking, or giving the tool back), and every dish must be ready before the rice on the stove is done.
A mutex is tied to one particular piece of data. Holding the wrong lock gives a false sense of safety: the data is still unprotected. Make sure you hold that dish's guard, not whatever tool happens to be in your hand.
A deadlock happens when two cooks each hold a tool the other needs and neither lets go: a circle of waiting. Mrs. Ijah holds the pestle and waits for the wok; Mrs. Yanti holds the wok and waits for the pestle. The kitchen freezes for good, and the rice burns. The classic cure is a global lock order: every cook takes the tools in the same order, say always the pestle before the wok, so the circle can never form.
Locking too much (coarse locking) is safe from races, but it kills parallelism: other cooks wait for a tool you aren't even using. Good granularity: lock only the data you touch, for as short a time as you can. Today the kitchen has a rule: no holding a tool that doesn't guard your dish.
The dining philosophers problem: cooks in a ring, each two neighbours sharing one tool. If everyone takes the tool on their left first, each cook holds one and waits for one: a perfect circle of waiting, and everyone freezes. The cure is a total order over all the tools. Number them pestle, wok, knife, and have every cook take the lowest number first. The last cook ends up going against the ring, and the ring breaks.
Careful when patching a race: adding locks on reflex can cause a deadlock if the order isn't the same everywhere. Here both cooks lack the wok, so the mi goreng is unguarded. Add the wok to both, but in the same order. Fixing one concurrency bug without planting another takes both disciplines at once.
pestle.Lock() before they touch the sambal, then start cooking.And more, 18 levels in all.