BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bslmt::Barrier Class Reference

#include <bslmt_barrier.h>

Detailed Description

This class defines a thread barrier.

See bslmt_barrier

Public Types

enum  { e_TIMED_OUT = -1 }
 

Public Member Functions

 Barrier (int numArrivals, bsls::SystemClockType::Enum clockType=bsls::SystemClockType::e_REALTIME)
 
 ~Barrier ()
 
void arrive ()
 
int timedWait (const bsls::TimeInterval &absTime)
 
void wait ()
 
bsls::SystemClockType::Enum clockType () const
 
int numArrivals () const
 
int numThreads () const
 

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

The value timedWait returns when a timeout occurs.

Enumerator
e_TIMED_OUT 

Constructor & Destructor Documentation

◆ Barrier()

bslmt::Barrier::Barrier ( int  numArrivals,
bsls::SystemClockType::Enum  clockType = bsls::SystemClockType::e_REALTIME 
)
inlineexplicit

Create a barrier that requires the specified numArrivals to unblock. Optionally specify a clockType indicating the type of the system clock against which the bsls::TimeInterval absTime timeouts passed to the timedWait method are to be interpreted (see {Supported Clock-Types} in the component-level documentation). If clockType is not specified then the realtime system clock is used.

Precondition
The behavior is undefined unless 0 < numArrivals.

◆ ~Barrier()

bslmt::Barrier::~Barrier ( )

Wait for all signaled threads to unblock and destroy this barrier. (See wait and timedWait below for the meaning of signaled.)

Note
Note that the behavior is undefined if a barrier is destroyed while one or more threads are waiting on it.

Member Function Documentation

◆ arrive()

void bslmt::Barrier::arrive ( )

Arrive on this barrier. If this is the last required arrival, signal all the threads that are currently waiting on this barrier to unblock and reset the state of this barrier to its initial state.

◆ clockType()

bsls::SystemClockType::Enum bslmt::Barrier::clockType ( ) const
inline

Return the clock type used for timeouts.

◆ numArrivals()

int bslmt::Barrier::numArrivals ( ) const
inline

Return the required number of arrivals before all waiting threads will unblock.

◆ numThreads()

int bslmt::Barrier::numThreads ( ) const
inline

Return the required number of arrivals before all waiting threads will unblock.

Deprecated:
Use numArrivals instead.

◆ timedWait()

int bslmt::Barrier::timedWait ( const bsls::TimeInterval absTime)

Arrive and block until the required number of arrivals have occurred, or until the specified absTime timeout expires. In the former case, signal all the threads that are currently waiting on this barrier to unblock, reset the state of this barrier to its initial state, and return 0. If this method times out before the required number of arrivals, the thread is released to proceed and ceases to contribute to the number of arrivals, and e_TIMED_OUT is returned. Any other return value indicates that an error has occurred. Errors are unrecoverable. After an error, the barrier may be destroyed, but any other use has undefined behavior. absTime is an absolute time represented as an interval from some epoch, which is determined by the clock indicated at construction (see {Supported Clock-Types} in the component-level documentation).

Note
Note that timedWait and wait should not generally be used together; if one or more threads called wait while others called timedWait, then if the thread(s) that called timedWait were to time out and not retry, the threads that called wait would never unblock.

◆ wait()

void bslmt::Barrier::wait ( )

Arrive and block until the required number of arrivals have occurred. Then signal all the threads that are currently waiting on this barrier to unblock and reset the state of this barrier to its initial state.

Note
Note that generally wait and timedWait should not be used together, for reasons explained in the documentation of timedWait.

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