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.

Use this page when the question is about the atomics model itself. If you need threads, mutexes, condition variables, futures, or stop tokens, jump to thread support. If you need the language rules behind data races and ordering, see the C++ memory model.

# 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 withWhy
An atomic wrapper that owns its own valuestd::atomicThe default entry point for atomic objects and operations in the standard library.
Atomic access to an existing object without changing its typestd::atomic_refLets you apply atomic operations to suitably aligned existing storage.
A minimal flag-style atomic primitivestd::atomic_flagThe lightweight test-and-set style primitive used for simple signaling/spin patterns.
To reason about visibility, ordering, and synchronizationstd::memory_orderOrdering modes are the key to understanding which cross-thread observations are guaranteed.
To block and wake on atomic state changesatomic_wait and notify operationsModern atomic waiting avoids hand-rolled spin loops in many use cases.
Ordering constraints without directly reading or writing an atomic objectatomic_thread_fence or atomic_signal_fenceFences provide ordering edges independent of a specific atomic variable access.
To know whether a design really stays lock-freeis_lock_free and is_always_lock_freeThey clarify implementation guarantees and when to escalate to higher-level synchronization.

# Atomic Families

FamilyKey pagesUse it for
Primary atomic object typesatomic, atomic_ref, atomic_flagOwning or non-owning atomic access to shared state.
Free atomic operationsatomic_load, atomic_store, atomic_exchange, atomic_compare_exchangeNon-member operation style, including overloads and historical/free-function APIs.
Read-modify-write helpersatomic_fetch_add, atomic_fetch_sub, atomic_fetch_and, atomic_fetch_or, atomic_fetch_xorCommon RMW patterns for counters, bitmasks, and synchronization state.
Ordering and fencesmemory_order, atomic_thread_fence, atomic_signal_fenceDefining how operations synchronize and how writes become visible across threads.
Wait/notify primitivesatomic_wait, atomic_notify_one, atomic_notify_all, atomic_flag_waitBlocking-style coordination built directly on atomics.
Auxiliary boundaries and legacy cornerskill_dependency, ATOMIC_FLAG_INIT, ATOMIC_VAR_INITNiche support points, legacy macros, and corners of the atomics surface.

# Member Ops Vs. Free Functions

StyleRepresentative APIsWhen to prefer it
Member operationsatomic::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 functionsatomic_load, atomic_store, atomic_exchange, atomic_compare_exchangeWhen interoperating with code that uses the free-function style or when overloads matter.
Flag-specific operationsatomic_flag_test_and_set, atomic_flag_clear, atomic_flag_testWhen 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.

# Boundary Lines

If you actually need...Go here
Thread objects, locks, condition variables, futures, stop tokens, or coordination primitivesThread support
The core language rules for data races, happens-before, and multi-threaded executionC++ language memory model, multi-threaded executions
C-side atomics or `_Atomic` compatibility instead of the C++ library surfaceC atomics