All Synchronization Objects

All Synchronization Objects

A compact scan page for mutexes, condition variables, semaphores, latches, barriers, and async coordination objects in the C++ standard library.

How to use this reference page

Use reference pages to confirm names, categories, nearby facilities, and the constraints that matter before writing or reviewing code.

  • Scan the top of the page first to identify the primary types, functions, or algorithm families involved.
  • Use the nearby-page links when your question is really about a companion header, related algorithm family, or broader subsystem.
  • Validate tricky behavior with a small compileable example before relying on memory for details like invalidation, ordering, allocation, or lifetime rules.

All Synchronization Objects

Mutex and lock types

Condition-based waiting

Semaphores and phase coordination

Futures and promise-based synchronization

Practical rules

Small worked example

#include <condition_variable>
#include <mutex>
#include <queue>

std::mutex guard;
std::condition_variable cv;
std::queue<int> jobs;

int pop_job() {
	std::unique_lock lock(guard);
	cv.wait(lock, [] { return !jobs.empty(); });
	int job = jobs.front();
	jobs.pop();
	return job;
}

This is the classic mutex-plus-condition-variable pairing: the mutex protects the queue invariant, and the condition variable lets workers sleep until that invariant changes.

Selection guide

Example in practice

#include <mutex>
#include <condition_variable>
#include <thread>

int main() {
    std::mutex guard;
    std::condition_variable cv;
    bool ready = false;

    std::jthread worker([&] {
        std::scoped_lock lock(guard);
        ready = true;
        cv.notify_one();
    });

    std::unique_lock lock(guard);
    cv.wait(lock, [&] { return ready; });
    return 0;
}