Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members File Members Related Pages

# ACE_Barrier Class Reference

Implements "barrier synchronization". More...

`#include <Synch.h>`

Inheritance diagram for ACE_Barrier:

[legend]
Collaboration diagram for ACE_Barrier:

[legend]
List of all members.

## Public Methods
| ACE_Barrier (u_int count, const ACE_TCHAR *name=0, void *arg=0)
| Initialize the barrier to synchronize <count> threads. More...
| ~ACE_Barrier (void)
| Default dtor. More...
int | wait (void)
| Block the caller until all <count> threads have called <wait> and then allow all the caller threads to continue in parallel. More...
void | dump (void) const
| Dump the state of an object. More...
## Public Attributes
| ACE_ALLOC_HOOK_DECLARE
| Declare the dynamic allocation hooks. More...
## Protected Attributes
ACE_Thread_Mutex | lock_
| Serialize access to the barrier state. More...
int | current_generation_
| Either 0 or 1, depending on whether we are the first generation of waiters or the next generation of waiters. More...
int | count_
| Total number of threads that can be waiting at any one time. More...
ACE_Sub_Barrier | sub_barrier_1_
| We keep two <sub_barriers>, one for the first "generation" of waiters, and one for the next "generation" of waiters. More...
ACE_Sub_Barrier | sub_barrier_2_
ACE_Sub_Barrier * | sub_barrier_ [2]
## Private Methods
void | operator= (const ACE_Barrier &)
| ACE_Barrier (const ACE_Barrier &)

## Detailed Description

Implements "barrier synchronization".

This class allows <count> number of threads to synchronize their completion of (one round of) a task, which is known as "barrier synchronization". After all the threads call <wait()> on the barrier they are all atomically released and can begin a new round.

This implementation uses a "sub-barrier generation numbering" scheme to avoid overhead and to ensure that all threads wait to leave the barrier correct. This code is based on an article from SunOpsis Vol. 4, No. 1 by Richard Marejka (Richard.Marejka@canada.sun.com).

## Constructor & Destructor Documentation

ACE_Barrier::ACE_Barrier | ( | u_int | count,
|  | const ACE_TCHAR * | name = 0,
|  | void * | arg = 0
| ) |

| Initialize the barrier to synchronize <count> threads.

ACE_Barrier::~ACE_Barrier | ( | void |  | ) |

| Default dtor.

ACE_Barrier::ACE_Barrier | ( | const ACE_Barrier & |  | ) | `[private]`

## Member Function Documentation

void ACE_Barrier::dump | ( | void |  | ) | const

| Dump the state of an object. Reimplemented in ACE_Thread_Barrier.

void ACE_Barrier::operator= | ( | const ACE_Barrier & |  | ) | `[private]`

int ACE_Barrier::wait | ( | void |  | ) |

| Block the caller until all <count> threads have called <wait> and then allow all the caller threads to continue in parallel.

## Member Data Documentation

ACE_Barrier::ACE_ALLOC_HOOK_DECLARE

| Declare the dynamic allocation hooks. Reimplemented in ACE_Thread_Barrier.

int ACE_Barrier::count_`[protected]`

| Total number of threads that can be waiting at any one time.

int ACE_Barrier::current_generation_`[protected]`

| Either 0 or 1, depending on whether we are the first generation of waiters or the next generation of waiters.

ACE_Thread_Mutex ACE_Barrier::lock_`[protected]`

| Serialize access to the barrier state.

ACE_Sub_Barrier* ACE_Barrier::sub_barrier_[2]`[protected]`

ACE_Sub_Barrier ACE_Barrier::sub_barrier_1_`[protected]`

| We keep two <sub_barriers>, one for the first "generation" of waiters, and one for the next "generation" of waiters. This efficiently solves the problem of what to do if all the first generation waiters don't leave the barrier before one of the threads calls wait() again (i.e., starts up the next generation barrier).

ACE_Sub_Barrier ACE_Barrier::sub_barrier_2_`[protected]`

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

- Synch.h
- Synch.cpp