Quick Links:

bal | bbl | bdl | bsl

Public Types | Public Member Functions

bslmt::Barrier Class Reference

#include <bslmt_barrier.h>

List of all members.

Public Types

enum  { e_TIMED_OUT = -1 }

Public Member Functions

 Barrier (int numArrivals, bsls::SystemClockType::Enum clockType=bsls::SystemClockType::e_REALTIME)
 Barrier (int numArrivals, const bsl::chrono::system_clock &)
 Barrier (int numArrivals, const bsl::chrono::steady_clock &)
 ~Barrier ()
void arrive ()
int timedWait (const bsls::TimeInterval &absTime)
template<class CLOCK , class DURATION >
int timedWait (const bsl::chrono::time_point< CLOCK, DURATION > &absTime)
void wait ()
bsls::SystemClockType::Enum clockType () const
int numArrivals () const
int numThreads () const

Detailed Description

This class defines a thread barrier.

See Component bslmt_barrier


Member Enumeration Documentation

anonymous enum
Enumerator:
e_TIMED_OUT 

Constructor & Destructor Documentation

bslmt::Barrier::Barrier ( int  numArrivals,
bsls::SystemClockType::Enum  clockType = bsls::SystemClockType::e_REALTIME 
) [explicit]

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. The behavior is undefined unless 0 < numArrivals.

bslmt::Barrier::Barrier ( int  numArrivals,
const bsl::chrono::system_clock &   
)

Create a barrier that requires the specified numArrivals to unblock. Use the realtime system clock as the clock against which the absTime timeouts passed to the timedWait methods are interpreted (see Supported Clock-Types in the component-level documentation). The behavior is undefined unless 0 < numArrivals.

bslmt::Barrier::Barrier ( int  numArrivals,
const bsl::chrono::steady_clock &   
)

Create a barrier that requires the specified numArrivals to unblock. Use the monotonic system clock as the clock against which the absTime timeouts passed to the timedWait methods are interpreted (see Supported Clock-Types in the component-level documentation). The behavior is undefined unless 0 < numArrivals.

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 that the behavior is undefined if a barrier is destroyed while one or more threads are waiting on it.


Member Function Documentation

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.

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

template<class CLOCK , class DURATION >
int bslmt::Barrier::timedWait ( const bsl::chrono::time_point< CLOCK, DURATION > &  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 associated with the time point. 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.

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 that generally wait and timedWait should not be used together, for reasons explained in the documentation of timedWait.

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

Return the clock type used for timeouts.

int bslmt::Barrier::numArrivals (  )  const

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

int bslmt::Barrier::numThreads (  )  const

DEPRECATED: Use numArrivals instead.

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


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