Header Reference: <semaphore>
Header Reference: <semaphore>
Counting and binary semaphore facilities from <semaphore>.
Header Reference: <semaphore>
Counting and binary semaphore facilities from <semaphore>.
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.
<semaphore>std::counting_semaphorestd::binary_semaphoreUse <semaphore> for permit-based coordination, throttling, and capacity management across threads.
#include <semaphore>
int main() {
std::counting_semaphore<3> slots{2};
slots.acquire();
slots.release();
}
The key idea is permits. A semaphore answers "how many operations may proceed now?" without forcing you to expose a mutex-protected container or condition predicate directly.
binary_semaphore for simple one-slot readiness or handoff signalscounting_semaphore when multiple concurrent permits or capacity slots exist#include <semaphore>
int main() {
std::binary_semaphore ready{0};
ready.release();
ready.acquire();
return 0;
}