Daily bit(e) of C++ | std::barrier
Daily bit(e) of C++ ♻️24, The synchronization mechanism for introducing phases of execution across multiple threads: std::barrier.
std::barrier is a C++20 synchronization primitive that enables the creation of synchronized execution phases across multiple threads.
A std::barrier is initialized with a count (the number of threads). When a thread arrives at a barrier, it can block until all other threads arrive or drop, decreasing the counter.
Unlike std::latch (which provides similar functionality), the std::barrier is re-usable and will call an optional completion function before unblocking the waiting threads.
Wow - that is nice.