Concurrency support library
Curated hub for C++ atomic operations: std::atomic, atomic_ref, atomic_flag, memory ordering, fences, wait/notify, and lock-free boundaries.
The atomics area covers the low-level synchronization primitives of the C++ memory model: atomic object types, free atomic functions, ordering constraints, fences, wait/notify operations, and the boundaries between lock-free coordination and higher-level thread primitives.
# Start Here
Atomic object types
Start here for the primary atomic templates and specializations used to make reads, writes, and RMW operations well-defined across threads.
Memory ordering
Use this route when correctness depends on acquire/release, sequential consistency, relaxed ordering, or the visibility of writes between threads.
Wait and notify
Choose this route for blocking-style coordination built on atomics rather than condition variables.
Fences and barriers
Use this route when ordering must be enforced independently of a specific atomic object access.
Free atomic functions
Start here when you are working with the non-member atomic API surface or historical/free-function style operations.
Lock-free boundaries
Use this route when you need to know whether operations are lock-free in practice, what progress guarantees exist, or when you should move up to mutex-based designs.
# Quick Map
| If you need... | Start with | Why |
|---|---|---|
| An atomic wrapper that owns its own value | std::atomic | The default entry point for atomic objects and operations in the standard library. |
| Atomic access to an existing object without changing its type | std::atomic_ref | Lets you apply atomic operations to suitably aligned existing storage. |
| A minimal flag-style atomic primitive | std::atomic_flag | The lightweight test-and-set style primitive used for simple signaling/spin patterns. |
| To reason about visibility, ordering, and synchronization | std::memory_order | Ordering modes are the key to understanding which cross-thread observations are guaranteed. |
| To block and wake on atomic state changes | atomic_wait and notify operations | Modern atomic waiting avoids hand-rolled spin loops in many use cases. |
| Ordering constraints without directly reading or writing an atomic object | atomic_thread_fence or atomic_signal_fence | Fences provide ordering edges independent of a specific atomic variable access. |
| To know whether a design really stays lock-free | is_lock_free and is_always_lock_free | They clarify implementation guarantees and when to escalate to higher-level synchronization. |
# Atomic Families
| Family | Key pages | Use it for |
|---|---|---|
| Primary atomic object types | atomic, atomic_ref, atomic_flag | Owning or non-owning atomic access to shared state. |
| Free atomic operations | atomic_load, atomic_store, atomic_exchange, atomic_compare_exchange | Non-member operation style, including overloads and historical/free-function APIs. |
| Read-modify-write helpers | atomic_fetch_add, atomic_fetch_sub, atomic_fetch_and, atomic_fetch_or, atomic_fetch_xor | Common RMW patterns for counters, bitmasks, and synchronization state. |
| Ordering and fences | memory_order, atomic_thread_fence, atomic_signal_fence | Defining how operations synchronize and how writes become visible across threads. |
| Wait/notify primitives | atomic_wait, atomic_notify_one, atomic_notify_all, atomic_flag_wait | Blocking-style coordination built directly on atomics. |
| Auxiliary boundaries and legacy corners | kill_dependency, ATOMIC_FLAG_INIT, ATOMIC_VAR_INIT | Niche support points, legacy macros, and corners of the atomics surface. |
# Member Ops Vs. Free Functions
| Style | Representative APIs | When to prefer it |
|---|---|---|
| Member operations | atomic::load, atomic::store, atomic::exchange, atomic::compare_exchange_* | When you already have an `std::atomic` or `std::atomic_ref` object and want the object-centric API. |
| Free functions | atomic_load, atomic_store, atomic_exchange, atomic_compare_exchange | When interoperating with code that uses the free-function style or when overloads matter. |
| Flag-specific operations | atomic_flag_test_and_set, atomic_flag_clear, atomic_flag_test | When a single-bit atomic state is enough and you do not need a general typed atomic object. |
# Practical Routes
I need to understand ordering
Start here when correctness depends on acquire/release, relaxed ordering, or the sequencing guarantees between threads.
I need atomic wait/notify
Start here when a thread should sleep until an atomic value changes instead of spinning continuously.
I need lock-free guarantees
Start here when performance or progress assumptions depend on whether operations actually stay lock-free on the target platform.
I may need higher-level primitives instead
If the problem is coordination rather than low-level shared-state correctness, mutexes, latches, semaphores, and condition variables may be the better fit.
thread support · mutex · latch
# Boundary Lines
| If you actually need... | Go here |
|---|---|
| Thread objects, locks, condition variables, futures, stop tokens, or coordination primitives | Thread support |
| The core language rules for data races, happens-before, and multi-threaded execution | C++ language memory model, multi-threaded executions |
| C-side atomics or `_Atomic` compatibility instead of the C++ library surface | C atomics |