UCommon
Public Member Functions
ucommon::Barrier Class Reference

A portable implementation of "barrier" thread sychronization. More...

#include <condition.h>

Inheritance diagram for ucommon::Barrier:
Inheritance graph
[legend]
Collaboration diagram for ucommon::Barrier:
Collaboration graph
[legend]

Public Member Functions

 Barrier (unsigned count)
 Construct a barrier with an initial size. More...
 
void dec (void)
 Reduce the number of threads required.
 
void inc (void)
 Dynamically increment the number of threads required.
 
unsigned operator++ (void)
 Alternative prefix form of the same increment operation. More...
 
unsigned operator-- (void)
 
void set (unsigned count)
 Dynamically alter the number of threads required. More...
 
void wait (void)
 Wait at the barrier until the count of threads waiting is reached.
 
bool wait (timeout_t timeout)
 Wait at the barrier until either the count of threads waiting is reached or a timeout has occurred. More...
 
 ~Barrier ()
 Destroy barrier and release pending threads.
 

Detailed Description

A portable implementation of "barrier" thread sychronization.

A barrier waits until a specified number of threads have all reached the barrier, and then releases all the threads together. This implementation works regardless of whether the thread library supports barriers since it is built from conditional. It also differs in that the number of threads required can be changed dynamically at runtime, unlike pthread barriers which, when supported, have a fixed limit defined at creation time. Since we use conditionals, another feature we can add is optional support for a wait with timeout.

Author
David Sugar dyfet.nosp@m.@gnu.nosp@m.telep.nosp@m.hony.nosp@m..org

Definition at line 588 of file condition.h.

Constructor & Destructor Documentation

◆ Barrier()

ucommon::Barrier::Barrier ( unsigned  count)

Construct a barrier with an initial size.

Parameters
countof threads required.

Member Function Documentation

◆ operator++()

unsigned ucommon::Barrier::operator++ ( void  )

Alternative prefix form of the same increment operation.

Returns
the current amount of threads.

◆ set()

void ucommon::Barrier::set ( unsigned  count)

Dynamically alter the number of threads required.

If the size is set below the currently waiting threads, then the barrier releases.

Parameters
countof threads required.

◆ wait()

bool ucommon::Barrier::wait ( timeout_t  timeout)

Wait at the barrier until either the count of threads waiting is reached or a timeout has occurred.

Parameters
timeoutto wait in milliseconds.
Returns
true if barrier reached, false if timer expired.

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