Concurrency Visualization

Mutexes, Semaphores & Deadlock • Diagram View
kunzhub / explainers
— moving squares on paper —

Select a scenario

Use the buttons below to explore how mutexes and semaphores work. Objects move on a flat plane with 3D shading and shadows for clarity.

Ready
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)