Thrill  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ThreadBarrierLocking Class Reference

Detailed Description

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

Definition at line 34 of file thread_barrier.hpp.

#include <thread_barrier.hpp>

Public Member Functions

 ThreadBarrierLocking (size_t thread_count)
 Creates a new barrier that waits for n threads. More...
 
template<typename Lambda = NoOperation<void>>
void Await (Lambda lambda=Lambda())
 Waits for n threads to arrive. More...
 
size_t step () const
 Return generation step counter. More...
 

Protected Attributes

size_t counts_ [2] = { 0, 0 }
 two counters: switch between them every run. More...
 
std::condition_variable cv_
 
std::mutex mutex_
 
size_t step_ = 0
 current counter used. More...
 
const size_t thread_count_
 number of threads More...
 

Constructor & Destructor Documentation

ThreadBarrierLocking ( size_t  thread_count)
inlineexplicit

Creates a new barrier that waits for n threads.

Definition at line 40 of file thread_barrier.hpp.

Member Function Documentation

void Await ( 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.

Definition at line 50 of file thread_barrier.hpp.

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

size_t step ( ) const
inline

Return generation step counter.

Definition at line 70 of file thread_barrier.hpp.

References ThreadBarrierLocking::step_.

Member Data Documentation

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

two counters: switch between them every run.

Definition at line 82 of file thread_barrier.hpp.

Referenced by ThreadBarrierLocking::Await().

std::condition_variable cv_
protected

Definition at line 76 of file thread_barrier.hpp.

Referenced by ThreadBarrierLocking::Await().

std::mutex mutex_
protected

Definition at line 75 of file thread_barrier.hpp.

Referenced by ThreadBarrierLocking::Await().

size_t step_ = 0
protected

current counter used.

Definition at line 85 of file thread_barrier.hpp.

Referenced by ThreadBarrierLocking::Await(), and ThreadBarrierLocking::step().

const size_t thread_count_
protected

number of threads

Definition at line 79 of file thread_barrier.hpp.

Referenced by ThreadBarrierLocking::Await().


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