tlx
ThreadBarrierMutex Class Reference

Implements a thread barrier using mutex locking and condition variables that can be used to synchronize threads. More...

#include <thread_barrier_mutex.hpp>

Public Member Functions

 ThreadBarrierMutex (size_t thread_count)
 Creates a new barrier that waits for n threads. More...
 
template<typename Lambda = NoOperation<void>>
void wait (Lambda lambda=Lambda())
 Waits for n threads to arrive. More...
 
template<typename Lambda = NoOperation<void>>
void wait_yield (Lambda lambda=Lambda())
 Waits for n threads to arrive. More...
 
size_t step () const
 return generation step bit: 0 or 1 More...
 

Protected Attributes

const size_t thread_count_
 number of threads More...
 
std::mutex mutex_
 mutex to synchronize access to the counters More...
 
std::condition_variable cv_
 condition variable everyone waits on for the last thread to signal More...
 
size_t counts_ [2]
 two counters: switch between them every run. More...
 
size_t step_
 current counter used. More...
 

Detailed Description

Implements a thread barrier using mutex locking and condition variables that can be used to synchronize threads.

Definition at line 25 of file thread_barrier_mutex.hpp.

Constructor & Destructor Documentation

ThreadBarrierMutex ( size_t  thread_count)
inlineexplicit

Creates a new barrier that waits for n threads.

Definition at line 31 of file thread_barrier_mutex.hpp.

Member Function Documentation

size_t step ( ) const
inline

return generation step bit: 0 or 1

Definition at line 76 of file thread_barrier_mutex.hpp.

void wait ( Lambda  lambda = Lambda())
inline

Waits for n threads to arrive.

This method blocks and returns as soon as n threads are waiting inside the method. Prior to continuing work, the lambda functor is called by the last thread entering the barrier.

Definition at line 42 of file thread_barrier_mutex.hpp.

void wait_yield ( Lambda  lambda = Lambda())
inline

Waits for n threads to arrive.

Identical with wait() for ThreadBarrierMutex.

This method blocks and returns as soon as n threads are waiting inside the method. Prior to continuing work, the lambda functor is called by the last thread entering the barrier.

Definition at line 71 of file thread_barrier_mutex.hpp.

Member Data Documentation

size_t counts_[2]
protected

two counters: switch between them every run.

Definition at line 91 of file thread_barrier_mutex.hpp.

std::condition_variable cv_
protected

condition variable everyone waits on for the last thread to signal

Definition at line 88 of file thread_barrier_mutex.hpp.

std::mutex mutex_
protected

mutex to synchronize access to the counters

Definition at line 85 of file thread_barrier_mutex.hpp.

size_t step_
protected

current counter used.

Definition at line 94 of file thread_barrier_mutex.hpp.

const size_t thread_count_
protected

number of threads

Definition at line 82 of file thread_barrier_mutex.hpp.


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