SeqAn3 3.4.0-rc.1
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
seqan3::detail::latch Class Reference

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.
 
latchoperator= (latch const &)=delete
 Deleted.
 
latchoperator= (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_tcounter
 The number of participating threads.
 
std::atomic< std::ptrdiff_tnum_waiting
 The number of waiting threads.
 

Detailed Description

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.

Note
This adapts the proposal for the c++ standard P0666R2 for latches and is likely to be changed according to the revisions of the proposal.

Constructor & Destructor Documentation

◆ latch()

seqan3::detail::latch::latch ( ptrdiff_t const  expected)
inlineexplicit

Constructs the latch with the expected number of threads.

Parameters
expectedThe number of threads participating in this synchronisation point.

Member Function Documentation

◆ arrive()

void seqan3::detail::latch::arrive ( ptrdiff_t  n = 1)
inlinenoexcept

Atomically decrements counter by n.

Parameters
nThe 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.

Exception

Guaranteed not to throw.

Thread safety

Thread-safe.

◆ arrive_and_wait()

void seqan3::detail::latch::arrive_and_wait ( ptrdiff_t  n = 1)
inlinenoexcept

Atomically decrements counter by n and blocks the calling thread.

Parameters
nThe 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.

Exception

Guaranteed not to throw.

Thread safety

Thread-safe.

◆ try_wait()

bool seqan3::detail::latch::try_wait ( ) const
inlinenoexcept

Checks if all participating threads have reached the synchronisation point.

Exception

Guaranteed not to throw.

Thread safety

Thread-safe.

◆ wait()

void seqan3::detail::latch::wait ( ) const
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.

Exception

Guaranteed not to throw.

Thread safety

Thread-safe.


The documentation for this class was generated from the following file:
Hide me