Spin barrier synchronization primitive.
More...
#include <spin_barrier.h>
Spin barrier synchronization primitive.
A barrier for a group of threads in the source code means any thread must stop at this point and cannot proceed until all other threads reach this barrier.
Spin version: threads will busy-wait and waste CPU cycles instead of yielding the CPU to another thread. Do not use spinlocks unless you are certain that you understand the consequences!
Thread-safe.
https://en.wikipedia.org/wiki/Barrier_(computer_science) https://en.wikipedia.org/wiki/Spinlock
- Examples
- threads_spin_barrier.cpp.
Definition at line 30 of file spin_barrier.h.
◆ SpinBarrier() [1/3]
CppCommon::SpinBarrier::SpinBarrier |
( |
int |
threads | ) |
|
|
inlineexplicitnoexcept |
Default class constructor.
- Parameters
-
threads | - Count of threads to wait at the barrier |
Definition at line 11 of file spin_barrier.inl.
◆ SpinBarrier() [2/3]
CppCommon::SpinBarrier::SpinBarrier |
( |
const SpinBarrier & |
| ) |
|
|
delete |
◆ SpinBarrier() [3/3]
◆ ~SpinBarrier()
CppCommon::SpinBarrier::~SpinBarrier |
( |
| ) |
|
|
default |
◆ operator=() [1/2]
◆ operator=() [2/2]
◆ threads()
int CppCommon::SpinBarrier::threads |
( |
| ) |
const |
|
inlinenoexcept |
Get the count of threads to wait at the barrier.
Definition at line 46 of file spin_barrier.h.
◆ Wait()
bool CppCommon::SpinBarrier::Wait |
( |
| ) |
|
|
inlinenoexcept |
Wait at the barrier until all other threads reach this barrier.
Will block.
- Returns
- 'true' for the last thread that reach barrier, 'false' for each of the remaining threads
- Examples
- threads_spin_barrier.cpp.
Definition at line 16 of file spin_barrier.inl.
The documentation for this class was generated from the following files: