In file thread/gmutex.hh:

class barrier

Barrier class.

Inheritance:


Public Methods

barrier (int count)
Create a barrier for count tasks
~barrier ()
Destroy a barrier
bool wait ()
wait at a barrier for all tasks

Protected Classes

struct subbarrier
subbarrier variables
pthread_cond_t wait_cv
condition for waiters at barrier
pthread_mutex_t wait_lk
mutex for waiters at barrier
int runners
number of running threads

Protected Fields

int maxcnt
Maximum number of runners
subbarrier sb [2]
Subbarriers
subbarrier* sbp
Current sub-barrier

Documentation

This class can be used to implement a barrier. In many applications, and especially numerical applications, while part of the algorithm can be parallelized, other parts are inherently sequential, as shown in the following:

    Thread1                             Thread2 through Threadn
  
    while(many_iterations) {            while(many_iterations) {

      sequential_computation
      --- Barrier ---                     --- Barrier ---
      parallel_computation                parallel_computation
    }                                   }
    

The nature of the parallel algorithms for such a computation is that little synchronization is required during the computation, but synchronization of all the threads employed is required to ensure that the sequential computation is finished before the parallel computation begins.

The barrier forces all the threads that are doing the parallel computation to wait until all threads involved have reached the barrier. When they've reached the barrier, they are released and begin computing together.

 
    Example:

    

barrier(int count)
Create a barrier for count tasks

~barrier()
Destroy a barrier

bool wait()
wait at a barrier for all tasks

struct subbarrier
subbarrier variables

pthread_cond_t wait_cv
condition for waiters at barrier

pthread_mutex_t wait_lk
mutex for waiters at barrier

int runners
number of running threads

int maxcnt
Maximum number of runners

subbarrier sb[2]
Subbarriers

subbarrier* sbp
Current sub-barrier


This class has no child classes.
Author:
DS, November 98
See Also:
Recursive mutex objects

alphabetic index hierarchy of classes


Please send questions and comments to zweizig_j@ligo.caltech.edu


generated by doc++