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

Detailed Description

Implements a cyclic barrier using atomics and a spin lock that can be used to synchronize threads.

This ThreadBarrier implementation was a lot faster in tests, but ThreadSanitizer shows data races (probably due to the generation counter).

Definition at line 95 of file thread_barrier.hpp.

+ Collaboration diagram for ThreadBarrierSpinning:

#include <thread_barrier.hpp>

Public Member Functions

 ThreadBarrierSpinning (size_t thread_count)
 Creates a new barrier that waits for n threads. More...
 
 ~ThreadBarrierSpinning ()
 
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

std::atomic< size_t > step_ { 0 }
 barrier synchronization generation More...
 
const size_t thread_count_
 number of threads More...
 
AtomicMovable< uint64_t > wait_time_ { 0 }
 
std::atomic< size_t > waiting_ { 0 }
 number of threads in spin lock More...
 

Constructor & Destructor Documentation

ThreadBarrierSpinning ( size_t  thread_count)
inlineexplicit

Creates a new barrier that waits for n threads.

Definition at line 101 of file thread_barrier.hpp.

Member Function Documentation

void Await ( Lambda  lambda = Lambda())
inline

Waits for n threads to arrive.

When they have arrive, execute lambda on the one thread, which arrived last. After lambda, step the generation counter.

This method blocks and returns as soon as n threads are waiting inside the method.

Definition at line 121 of file thread_barrier.hpp.

References ThreadBarrierSpinning::step_, ThreadBarrierSpinning::thread_count_, and ThreadBarrierSpinning::waiting_.

Referenced by FlowControlChannel::AllGather(), FlowControlChannel::AllReduce(), FlowControlChannel::Barrier(), FlowControlChannel::Broadcast(), FlowControlChannel::ExPrefixSumTotal(), FlowControlChannel::LocalBarrier(), FlowControlChannel::Predecessor(), FlowControlChannel::PrefixSumBase(), and FlowControlChannel::Reduce().

size_t step ( ) const
inline

Return generation step counter.

Definition at line 144 of file thread_barrier.hpp.

References ThreadBarrierSpinning::step_.

Referenced by FlowControlChannel::GetNextStep().

Member Data Documentation

std::atomic<size_t> step_ { 0 }
protected

barrier synchronization generation

Definition at line 156 of file thread_barrier.hpp.

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

const size_t thread_count_
protected

number of threads

Definition at line 150 of file thread_barrier.hpp.

Referenced by ThreadBarrierSpinning::Await(), and ThreadBarrierSpinning::~ThreadBarrierSpinning().

AtomicMovable<uint64_t> wait_time_ { 0 }
protected

Definition at line 158 of file thread_barrier.hpp.

Referenced by ThreadBarrierSpinning::~ThreadBarrierSpinning().

std::atomic<size_t> waiting_ { 0 }
protected

number of threads in spin lock

Definition at line 153 of file thread_barrier.hpp.

Referenced by ThreadBarrierSpinning::Await().


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