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

Barrier synchronization primitive. More...

#include <barrier.h>

Public Member Functions

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

Detailed Description

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.

Thread-safe.

https://en.wikipedia.org/wiki/Barrier_(computer_science)

Examples
threads_barrier.cpp.

Definition at line 27 of file barrier.h.

Constructor & Destructor Documentation

◆ Barrier() [1/3]

CppCommon::Barrier::Barrier ( int  threads)
explicit

Default class constructor.

Parameters
threads- Count of threads to wait at the barrier

Definition at line 122 of file barrier.cpp.

◆ Barrier() [2/3]

CppCommon::Barrier::Barrier ( const Barrier )
delete

◆ Barrier() [3/3]

CppCommon::Barrier::Barrier ( Barrier &&  barrier)
delete

◆ ~Barrier()

CppCommon::Barrier::~Barrier ( )

Definition at line 133 of file barrier.cpp.

Member Function Documentation

◆ operator=() [1/2]

Barrier& CppCommon::Barrier::operator= ( Barrier &&  barrier)
delete

◆ operator=() [2/2]

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

◆ threads()

int CppCommon::Barrier::threads ( ) const
noexcept

Get the count of threads to wait at the barrier.

Definition at line 139 of file barrier.cpp.

◆ Wait()

bool CppCommon::Barrier::Wait ( )

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_barrier.cpp.

Definition at line 141 of file barrier.cpp.


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