Semaphore
Previous: Concurrency
A semaphore is a synchronization primitive similar to locks and condition
variables. It provides two operations, signal() and wait(), and keeps
track of a count (an integer).
wait: Decrements the semaphore’s count. If the new value is less than zero, it blocks the calling thread.signal: Increments the semaphore’s count. If the count was negative before the increment, it wakes one waiting thread and moves it to the ready queue.