— moving squares on paper —
Threads: 4 • Active: 0 • Blocked: 0
Running
Waiting / Blocked
In Critical Section
Holding Lock/Permit
How these primitives work (diagram view)
Mutex (Mutual Exclusion)
A single "key" (the yellow lock block) that only one thread square can hold. Other threads wait in line on the plane until the key is released and slides to the next waiter. Clear ownership transfer.
Semaphore (Counting)
A limited number of permit tokens (purple blocks). Threads can grab a permit if one is free and move into the critical area. When permits run out, new arrivals queue on the paper. Releasing returns a token to the pool.
Deadlock
Two thread squares each grab one lock, then try to grab the one the other holds. They freeze in a crossed position. The scene highlights the cycle so you can see exactly why progress stops.
Key observations (watch the plane)
- Atomic claim — A thread square moves to the lock and "claims" it in one clean motion. No other square can claim at the same time.
- Queue discipline — Blocked squares line up visibly. When a lock frees, the front of the queue moves forward and claims it.
- Permit handoff — In semaphore mode you see tokens slide from the pool to a thread and back again.
- Circular wait — In deadlock the two squares end up pointing at each other's locks with no way forward.