Documentation Home >> Headers >> <jss/experimental_barrier.hpp> Header >> std::experimental::flex_barrier class

The flex_barrier class is a barrier for a variable number of threads. The initial number of participating threads is specified in the constructor, but the number of participating threads can be varied by the supplied completion function. The first N threads to call either std::experimental::flex_barrier::arrive_and_wait or std::experimental::flex_barrier::arrive_and_drop form the set of participating threads, where N is the current number of participating threads.

The completion function allows additional synchronization or notification to be done when all participating threads have arrived at the barrier, and allows the number of participating threads to be changed. It can be any Callable type which is MoveConstructible, and which can be invoked with a single ptrdiff_t parameter, returning a value implicitly convertible to a ptrdiff_t.

When all participating threads have arrived at the barrier, the completion function is called with the current number of participating threads (which may already have been reduced due to calls to std::experimental::flex_barrier::arrive_and_drop).

If the completion function returns less than 0 then the number of participating threads is unchanged, otherwise the number of participating threads in the next cycle is set to the returned value.

class flex_barrier{
public:
    explicit flex_barrier(ptrdiff_t num_threads);
    template<typename CompletionFunc>
    explicit flex_barrier(ptrdiff_t num_threads,CompletionFunc comp_func):
    ~flex_barrier();

    flex_barrier(flex_barrier const&)=delete;
    flex_barrier& operator=(flex_barrier const&)=delete;

    void arrive_and_drop();
    void arrive_and_wait();
};
Header

#include <experimental/barrier>

See Also