The <experimental/barrier>
header provides two barrier
classes, which provide a means of ensuring that a given set of threads are
synchronized.
The participating threads block at a synchronization point by calling arrive_and_wait
. Once all the threads have
reached the synchronization point, one thread calls the completion function
(if any), and then all participating threads are unblocked.
Threads may signal that they no longer wish to participate in the synchronization
by calling arrive_and_drop
on the barrier instead. This will contribute to unlocking any blocked threads,
without blocking the calling thread. The calling thread may not then call
any member functions on the barrier again.
namespace std{ namespace experimental{ class barrier; class flex_barrier; } }
The std::experimental::barrier
class provides a basic barrier with no completion function. The std::experimental::flex_barrier
class allows you to provide a completion function. The completion
function can reduce the number of threads that participate in the synchronization.