tlx
|
Implements a thread barrier using atomics and a spin lock that can be used to synchronize threads. More...
#include <thread_barrier_spin.hpp>
Public Member Functions | |
ThreadBarrierSpin (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, yield thread while spinning. More... | |
size_t | step () const |
Return generation step counter. More... | |
Protected Attributes | |
const size_t | thread_count_ |
number of threads, minus one due to comparison needed in loop More... | |
std::atomic< size_t > | waiting_ |
number of threads in spin lock More... | |
std::atomic< size_t > | step_ |
barrier synchronization generation More... | |
Implements a thread barrier using atomics and a spin lock that can be used to synchronize threads.
This ThreadBarrier implementation was a lot faster in tests than ThreadBarrierMutex, but ThreadSanitizer shows data races (probably due to the generation counter).
Definition at line 29 of file thread_barrier_spin.hpp.
|
inlineexplicit |
Creates a new barrier that waits for n threads.
Definition at line 35 of file thread_barrier_spin.hpp.
|
inline |
Return generation step counter.
Definition at line 97 of file thread_barrier_spin.hpp.
|
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 47 of file thread_barrier_spin.hpp.
|
inline |
Waits for n threads to arrive, yield thread while spinning.
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 76 of file thread_barrier_spin.hpp.
|
protected |
barrier synchronization generation
Definition at line 109 of file thread_barrier_spin.hpp.
|
protected |
number of threads, minus one due to comparison needed in loop
Definition at line 103 of file thread_barrier_spin.hpp.
|
protected |
number of threads in spin lock
Definition at line 106 of file thread_barrier_spin.hpp.