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.
All Synchronization Objects
A compact scan page for mutexes, condition variables, semaphores, latches, barriers, and async coordination objects in the C++ standard library.
Use reference pages to confirm names, categories, nearby facilities, and the constraints that matter before writing or reviewing code.
std::mutexstd::recursive_mutexstd::timed_mutexstd::recursive_timed_mutexstd::shared_mutexstd::shared_timed_mutexstd::lock_guardstd::unique_lockstd::scoped_lockstd::shared_lockstd::condition_variablestd::condition_variable_anystd::notify_all_at_thread_exitstd::counting_semaphorestd::binary_semaphorestd::latchstd::barrierstd::futurestd::shared_futurestd::promisestd::packaged_taskstd::async#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.
mutex plus condition_variable for shared-state waiting on predicatesshared_mutex when reads dominate and concurrent readers matter more than simple lockingbinary_semaphore or counting_semaphore for permit-style coordinationlatch or barrier when threads must reach a common phase pointfuture or promise when the handoff includes a result, exception, or completion state#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;
}