AlgoPlus//structures / semaphore
Read the theory

Synchronization · Mutex / Semaphore

A binary semaphore serialises entry to the critical section, preventing lost updates.

Semaphore
Counter
0
Blocked
0
Legend
In critical section
Blocked (queued)
Race / lock held
AI Tutor Workspace
In a nutshell
A semaphore is a gatekeeper with a count of available passes. To enter a shared section a thread asks for a pass (wait); if none is free it lines up and waits. On leaving it returns the pass (signal) and the next in line is let through. With a single pass — a binary semaphore, or mutex — exactly one thread touches the shared data at a time, so their updates can't overwrite each other.
Ready
Press play to begin the cinematic walkthrough.
A semaphore is a gate with a counter. wait() takes a permit or blocks; signal() returns one and wakes a waiter. A binary semaphore (mutex) lets exactly one thread into the critical section, so concurrent updates can't clobber each other.
Key terms
Go deeper in the lesson
Read the full theory, intuition & complexity for Synchronization · Mutex / Semaphore.