Header Reference: <latch>
Header Reference: <latch>
One-shot coordination point facilities from <latch>.
Header Reference: <latch>
One-shot coordination point facilities from <latch>.
Use reference pages to confirm names, categories, nearby facilities, and the constraints that matter before writing or reviewing code.
Header reference pages are meant to answer a practical question quickly: what this header provides, when to reach for it, and which usage rules are easiest to get wrong.
<latch>std::latchUse <latch> when a fixed number of participating operations must all arrive before one-time continuation can proceed.
std::latch is one-shot. Use std::barrier when repeated phase synchronization is required.#include <latch>
#include <thread>
int main() {
std::latch ready{2};
std::jthread a([&] { ready.count_down(); });
std::jthread b([&] { ready.count_down(); });
ready.wait();
}
This is the common latch shape: several startup or completion events must happen once, and only then may the waiting thread continue.
std::latch for one-time coordination gatesstd::barrier when the same set of participants repeats across multiple phases#include <latch>
int main() {
std::latch gate{1};
gate.count_down();
gate.wait();
return 0;
}