SeqAn3 3.4.0-rc.1
The Modern C++ library for sequence analysis.
|
A single-use synchronisation point to coordinate concurrent threads. More...
#include <seqan3/utility/parallel/detail/latch.hpp>
Public Member Functions | |
void | arrive (ptrdiff_t n=1) noexcept |
Atomically decrements counter by n . | |
void | arrive_and_wait (ptrdiff_t n=1) noexcept |
Atomically decrements counter by n and blocks the calling thread. | |
bool | try_wait () const noexcept |
Checks if all participating threads have reached the synchronisation point. | |
void | wait () const |
Waits for all participating threads to arrive at the synchronisation point. | |
Constructors, destructor and assignment | |
Not default constructible nor copyable or movable. | |
latch ()=delete | |
Deleted. | |
latch (latch const &)=delete | |
Deleted. | |
latch (latch &&)=delete | |
Deleted. | |
latch & | operator= (latch const &)=delete |
Deleted. | |
latch & | operator= (latch &&)=delete |
Deleted. | |
~latch () | |
Destructs the latch and waits for all participating threads to arrive. | |
latch (ptrdiff_t const expected) | |
Constructs the latch with the expected number of threads. | |
Private Attributes | |
std::atomic< std::ptrdiff_t > | counter |
The number of participating threads. | |
std::atomic< std::ptrdiff_t > | num_waiting |
The number of waiting threads. | |
A single-use synchronisation point to coordinate concurrent threads.
A latch is a thread coordination mechanism that allows any number of threads to block until an expected count is summed (exactly) by threads that arrived at the latch. The expected count is set when the latch is constructed. An individual latch is a single-use object; once the count has been reached, the latch cannot be reused. This implementation uses a lock-free mechanism if the atomic operations on the respective platform are lock-free.
|
inlineexplicit |
Constructs the latch with the expected number of threads.
expected | The number of threads participating in this synchronisation point. |
|
inlinenoexcept |
Atomically decrements counter by n
.
n | The value to subtract. |
Arrives at the synchronisation point with n
count without waiting. If n
is less than 0 or greater then the current count, then this operation results in undefined behaviour for all other participating threads.
Guaranteed not to throw.
Thread-safe.
|
inlinenoexcept |
Atomically decrements counter by n
and blocks the calling thread.
n | The value to subtract. |
Arrives at the synchronisation point with n
count and blocks the calling thread until all participating threads have arrived. If n
is less than 0 or greater then the current count, then this operation results in undefined behaviour for all other participating threads.
Guaranteed not to throw.
Thread-safe.
|
inlinenoexcept |
Checks if all participating threads have reached the synchronisation point.
Guaranteed not to throw.
Thread-safe.
|
inline |
Waits for all participating threads to arrive at the synchronisation point.
If counter == 0 returns immediately, otherwise blocks the calling thread at the synchronisation point. This implementation uses a seqan3::spin_delay to wait for the value.
Guaranteed not to throw.
Thread-safe.