Version 4 of semaphores

Updated 2003-05-30 21:17:11

Invented by Edsger Dijkstra as a low-level synchronization primitive.

A semaphore holds an integer >= 0, and supports two atomic operations: P(S) (or wait) and V(S) (or signal). V(S) atomically increments the value of S; P(S) atomically decrements it if S > 0, otherwise it blocks until some other task executes V(S).

One common use of semaphores is to implement mutexes (mutual exclusion locks). Each shared resource is guarded by a semaphore; the resource is unlocked when S = 1 and locked when S = 0. P(S) acquires the lock (blocking if necessary) and V(S) releases it (awakening any tasks blocked waiting for the lock). By initializing P to some number n > 0, semaphores can also support n-at-a-time access.

P and V stand for the Dutch words proberen (to test) and verhogen (to increment).