Barrier class

Implements a simple barrier thread-coordination mechanism using a condition variable and mutex.

Generally you would construct a Barrier of a certain size, and then pass it to the parallel tasks. The tasks that call Barrier::block wait until the specified number of tasks have reached the barrier. Here is a simple example:

Barrier *barrier = new Barrier(5);
parallel_for(blocked_range<uint32_t>(0, 15),
             [barrier](blocked_range<uint32_t> range)
             {
                // do some work

                // now wait until 5 threads have finished the above work
                if (barrier->block())
                    delete barrier;

                // we now know that 5 threads have reached and passed the barrier
             });

Public functions

auto block() -> bool
Returns true to only one thread (which should delete the barrier).