hpx::binary_semaphore#

Defined in header hpx/semaphore.hpp.

See Public API for a list of names and headers that are part of the public HPX API.

namespace hpx
class binary_semaphore#
#include <binary_semaphore.hpp>

A binary semaphore is a semaphore object that has only two states. binary_semaphore is an alias for specialization of hpx::counting_semaphore with LeastMaxValue being 1. HPX’s implementation of binary_semaphore is more efficient than the default implementation of a counting semaphore with a unit resource count (hpx::counting_semaphore).

Public Functions

binary_semaphore(binary_semaphore const&) = delete#
binary_semaphore &operator=(binary_semaphore const&) = delete#
binary_semaphore(binary_semaphore&&) = delete#
binary_semaphore &operator=(binary_semaphore&&) = delete#
explicit binary_semaphore(std::ptrdiff_t value = 1)#

Constructs an object of type hpx::binary_semaphore with the internal counter initialized to value.

Parameters

value – The initial value of the internal semaphore lock count. Normally this value should be zero (which is the default), values greater than zero are equivalent to the same number of signals pre-set, and negative values are equivalent to the same number of waits pre-set.

~binary_semaphore() = default#
void release(std::ptrdiff_t update = 1)#

Atomically increments the internal counter by the value of update. Any thread(s) waiting for the counter to be greater than 0, such as due to being blocked in acquire, will subsequently be unblocked.

Note

Synchronization: Strongly happens before invocations of try_acquire that observe the result of the effects.

Throws

std::system_error

Parameters

update – the amount to increment the internal counter by

Pre

Both update >= 0 and update <= max() - counter are true, where counter is the value of the internal counter.

bool try_acquire() noexcept#

Tries to atomically decrement the internal counter by 1 if it is greater than 0; no blocking occurs regardless.

Returns

true if it decremented the internal counter, otherwise false

void acquire()#

Repeatedly performs the following steps, in order:

  • Evaluates try_acquire. If the result is true, returns.

Blocks on *this until counter is greater than zero.

Throws

std::system_error

Returns

void.

bool try_acquire_until(hpx::chrono::steady_time_point const &abs_time)#

Tries to atomically decrement the internal counter by 1 if it is greater than 0; otherwise blocks until it is greater than 0 and can successfully decrement the internal counter, or the abs_time time point has been passed.

Parameters

abs_time – the earliest time the function must wait until in order to fail

Throws

std::system_error

Returns

true if it decremented the internal counter, otherwise false.

bool try_acquire_for(hpx::chrono::steady_duration const &rel_time)#

Tries to atomically decrement the internal counter by 1 if it is greater than 0; otherwise blocks until it is greater than 0 and can successfully decrement the internal counter, or the rel_time duration has been exceeded.

Throws

std::system_error

Parameters

rel_time – the minimum duration the function must wait for to fail

Returns

true if it decremented the internal counter, otherwise false

Public Static Functions

static constexpr std::ptrdiff_t max() noexcept#

Returns The maximum value of counter. This value is greater than or equal to LeastMaxValue.

Returns

The internal counter’s maximum possible value, as a std::ptrdiff_t.