barrier.h 486 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27

#ifndef PLS_BARRIER_H
#define PLS_BARRIER_H

#include <pthread.h>


/**
 * Provides standard barrier behaviour.
 * `count` threads have to call `wait()` before any of the `wait()` calls returns,
 * thus blocking all threads until everyone reached the barrier.
 *
 * PORTABILITY:
 * Current implementation is based on pthreads.
 */
class barrier {
  pthread_barrier_t barrier_;

 public:
  explicit barrier(unsigned int count);
  ~barrier();

  void wait();
};


#endif //PLS_BARRIER_H