Thrill  0.1
ThreadBarrierMutex Class Reference

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.

#include <thread_barrier_mutex.hpp>

Public Member Functions

 ThreadBarrierMutex (size_t thread_count)
 Creates a new barrier that waits for n threads. More...
 
size_t step () const
 return generation step bit: 0 or 1 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...
 

Protected Attributes

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

Constructor & Destructor Documentation

◆ ThreadBarrierMutex()

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

◆ step()

size_t step ( ) const
inline

return generation step bit: 0 or 1

Definition at line 76 of file thread_barrier_mutex.hpp.

References ThreadBarrierMutex::step_.

◆ wait()

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.

References ThreadBarrierMutex::counts_, ThreadBarrierMutex::cv_, ThreadBarrierMutex::mutex_, ThreadBarrierMutex::step_, and ThreadBarrierMutex::thread_count_.

Referenced by tlx::parallel_mergesort_detail::parallel_sort_mwms_pu(), and ThreadBarrierMutex::wait_yield().

◆ wait_yield()

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.

References ThreadBarrierMutex::wait().

Member Data Documentation

◆ counts_

size_t counts_[2] = { 0, 0 }
protected

two counters: switch between them every run.

Definition at line 91 of file thread_barrier_mutex.hpp.

Referenced by ThreadBarrierMutex::wait().

◆ cv_

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.

Referenced by ThreadBarrierMutex::wait().

◆ mutex_

std::mutex mutex_
protected

mutex to synchronize access to the counters

Definition at line 85 of file thread_barrier_mutex.hpp.

Referenced by ThreadBarrierMutex::wait().

◆ step_

size_t step_ = 0
protected

current counter used.

Definition at line 94 of file thread_barrier_mutex.hpp.

Referenced by ThreadBarrierMutex::step(), and ThreadBarrierMutex::wait().

◆ thread_count_

const size_t thread_count_
protected

number of threads

Definition at line 82 of file thread_barrier_mutex.hpp.

Referenced by ThreadBarrierMutex::wait().


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