CppCommon  1.0.4.1
C++ Common Library
Public Member Functions | List of all members
CppCommon::SpinBarrier Class Reference

Spin barrier synchronization primitive. More...

#include <spin_barrier.h>

Public Member Functions

 SpinBarrier (int threads) noexcept
 Default class constructor. More...
 
 SpinBarrier (const SpinBarrier &)=delete
 
 SpinBarrier (SpinBarrier &&)=delete
 
 ~SpinBarrier ()=default
 
SpinBarrieroperator= (const SpinBarrier &)=delete
 
SpinBarrieroperator= (SpinBarrier &&)=delete
 
int threads () const noexcept
 Get the count of threads to wait at the barrier. More...
 
bool Wait () noexcept
 Wait at the barrier until all other threads reach this barrier. More...
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ 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]

CppCommon::SpinBarrier::SpinBarrier ( SpinBarrier &&  )
delete

◆ ~SpinBarrier()

CppCommon::SpinBarrier::~SpinBarrier ( )
default

Member Function Documentation

◆ operator=() [1/2]

SpinBarrier& CppCommon::SpinBarrier::operator= ( const SpinBarrier )
delete

◆ operator=() [2/2]

SpinBarrier& CppCommon::SpinBarrier::operator= ( SpinBarrier &&  )
delete

◆ 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: