Semaphores
Semaphores handle all of your synchronization needs with one elegant but confusing abstraction.
- controls allocation of a resource with multiple instances
- a non-negative integer with special operations and properties
initialize to arbitrary value with Init operation
“souped up” increment (Up or V) and decrement (Down or P)
- atomic sleep/wakeup behavior implicit in P and V
P does an atomic sleep, if the semaphore value is zero.
P means “probe”; it cannot decrement until the semaphore is positive.
V does an atomic wakeup.
num(P) <= num(V) + init