11 #ifndef TLX_THREAD_BARRIER_MUTEX_HEADER 12 #define TLX_THREAD_BARRIER_MUTEX_HEADER 16 #include <condition_variable> 41 template <
typename Lambda = NoOperation<
void> >
42 void wait(Lambda lambda = Lambda()) {
43 std::unique_lock<std::mutex> lock(
mutex_);
45 size_t current =
step_;
70 template <
typename Lambda = NoOperation<
void> >
88 std::condition_variable
cv_;
99 #endif // !TLX_THREAD_BARRIER_MUTEX_HEADER std::mutex mutex_
mutex to synchronize access to the counters
std::condition_variable cv_
condition variable everyone waits on for the last thread to signal
size_t step() const
return generation step bit: 0 or 1
ThreadBarrierMutex(size_t thread_count)
Creates a new barrier that waits for n threads.
void wait(Lambda lambda=Lambda())
Waits for n threads to arrive.
void wait_yield(Lambda lambda=Lambda())
Waits for n threads to arrive.
size_t counts_[2]
two counters: switch between them every run.
Implements a thread barrier using mutex locking and condition variables that can be used to synchroni...
size_t step_
current counter used.
const size_t thread_count_
number of threads