Class semaphore

Class Documentation

class concore::v1::semaphore

The classic “semaphore” synchronization primitive.

It atomically maintains an internal count. The count can always be increased by calling signal(), which is always a non-blocking call. When calling wait(), the count is decremented; if the count is still positive the call will be non-blocking; if the count goes below zero, the call to wait() will block until some other thread calls signal().

See

binary_semaphore

Public Functions

semaphore(int start_count = 0)

Constructs a new semaphore instance.

Parameters
  • start_count: The value that the semaphore count should have at start

~semaphore()

Destructor.

semaphore(const semaphore&) = delete

Copy constructor is DISABLED.

void operator=(const semaphore&) = delete

Copy assignment is DISABLED.

semaphore(semaphore&&) = delete

Move constructor is DIABLED.

void operator=(semaphore&&) = delete

Move assignment is DIABLED.

void wait()

Decrement the internal count and wait on the count to be positive.

If the count of the semaphore is positive this will decrement the count and return immediately. On the other hand, if the count is 0, it wait for it to become positive before decrementing it and returning.

See

signal()

void signal()

Increment the internal count.

If there are at least one thread that is blocked inside a wait() call, this will wake up a waiting thread.

See

wait()