tlx
|
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... | |
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.
|
inlineexplicit |
Creates a new barrier that waits for n threads.
Definition at line 31 of file thread_barrier_mutex.hpp.
|
inline |
return generation step bit: 0 or 1
Definition at line 76 of file thread_barrier_mutex.hpp.
|
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.
|
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.
|
protected |
two counters: switch between them every run.
Definition at line 91 of file thread_barrier_mutex.hpp.
|
protected |
condition variable everyone waits on for the last thread to signal
Definition at line 88 of file thread_barrier_mutex.hpp.
|
protected |
mutex to synchronize access to the counters
Definition at line 85 of file thread_barrier_mutex.hpp.
|
protected |
current counter used.
Definition at line 94 of file thread_barrier_mutex.hpp.
|
protected |
number of threads
Definition at line 82 of file thread_barrier_mutex.hpp.