std::barrier
Get detailed information on std::barrier.
We'll cover the following...
We'll cover the following...
Introduction
An std::barrier is similar to a std::latch.
There are two differences between a std::latch and a std::barrier. First, you can use a std::barrier more than once, and second, you can set the counter for the next step (iteration). Immediately after the counter becomes zero, the so-called completion step starts. In this completion step, a callable is invoked. The std::barrier gets its callable in its constructor.
The completion step performs the following steps:
- All threads are blocked.
- An arbitrary thread is unblocked and executes the callable.
- If the completion step is done, all threads are unblocked.
Example and analysis
Now, let us have a closer look at the interface of a std::barrier.