Semaphores
Semaphores are a synchronisation mechanism used to control concurrent access to a shared resource. A counting semaphore is a special semaphore which has a counter that is bigger than zero. The counter is initialised in the constructor. Acquiring the semaphore decreases the counter and releasing the semaphore increases the counter. If a thread tries to acquire the semaphore when the counter is zero, the thread will block until another thread increments the counter by releasing the semaphore.
Method | Description |
---|---|
counting_semaphore::max() |
Return the maximum value of the counter . |
sem.release(upd = 1) |
Atomically increases counter by upd . |
sem.acquire() |
Performs sem.try_acquire and blocks until counter is greater than zero. |
sem.try_acquire() |
Atomically decrements the counter . |
sem.try_acquire_for(reTime... |