Skip to main content
  1. Glossaries/

Lock / Mutex / Semaphore

·1 min
Clément Sauvage
Author
Clément Sauvage
I like to make softwares

Lock: A general term for any synchronization mechanism that prevents concurrent access to a shared resource. When a thread acquires a lock, others must wait until it’s released.

Mutex: A lock that only allows one thread in at a time, with strict ownership. Only the thread that locked it can unlock it. If another thread tries to acquire an already locked mutex, it blocks until the owner releases it.

Semaphore: A counter-based lock that allows up to N threads to access a resource simultaneously. Any thread can increment or decrement the counter, making it useful for rate-limiting or signaling between threads, not just mutual exclusion.