dispenso
A library for task parallelism
 
Loading...
Searching...
No Matches
dispenso::Latch Class Reference

#include <latch.h>

Public Member Functions

 Latch (uint32_t threadGroupCount) noexcept
 
void count_down (uint32_t n=1) noexcept
 
bool try_wait () const noexcept
 
void wait () const noexcept
 
void arrive_and_wait () noexcept
 

Detailed Description

A class which can be used for barrier scenarios. See e.g. https://en.cppreference.com/w/cpp/thread/latch

Definition at line 26 of file latch.h.

Constructor & Destructor Documentation

◆ Latch()

dispenso::Latch::Latch ( uint32_t  threadGroupCount)
inlineexplicitnoexcept

Construct a latch with expected number of threads to wait on.

Parameters
threadGroupCountThe number of threads in the group.

Definition at line 33 of file latch.h.

Member Function Documentation

◆ arrive_and_wait()

void dispenso::Latch::arrive_and_wait ( )
inlinenoexcept

Decrement the counter and wait

Definition at line 66 of file latch.h.

◆ count_down()

void dispenso::Latch::count_down ( uint32_t  n = 1)
inlinenoexcept

Decrement the counter in a non-blocking manner.

Definition at line 38 of file latch.h.

◆ try_wait()

bool dispenso::Latch::try_wait ( ) const
inlinenoexcept

See if the count has been reduced to zero, indicating all necessary threads have synchronized.

Note
try_wait is a misnomer, as the function never blocks. We kept the name to match C++20 API.
Returns
true only if the internal counter has reached zero.

Definition at line 52 of file latch.h.

◆ wait()

void dispenso::Latch::wait ( ) const
inlinenoexcept

Wait for all threads to have synchronized.

Definition at line 59 of file latch.h.


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