On this page
_Atomic
Prev: volatile | Up: builtins | Next: _Thread_local
Rel: stdatomic.h
Ref: cppreference — _Atomic
Tags: #public #prog #c #builtins #tier/specialized
Availability
Built-in (Type Qualifier (C11)) — requires no #include header.
Syntax & Overview
_Atomic T x;
Declares an object supporting data-race-free atomic operations across threads.
Notes & Pitfalls
- Lock-free shared state (C11): Pair with
<stdatomic.h>foratomic_fetch_add,atomic_load, and memory-order control. - Compound read-modify-write via
+=uses sequential consistency by default.
Example
#include <assert.h>
#include <stdatomic.h>
int main(void) {
_Atomic int counter = 0;
atomic_fetch_add(&counter, 5);
assert(atomic_load(&counter) == 5);
}
Linked from
Related notes
- tuts/c/builtins/_Thread_local Linked here; links to this page; shared tags: #builtins, #c, #prog, #tier
- tuts/c/builtins/volatile Linked here; links to this page; shared tags: #builtins, #c, #prog, #tier
- tuts/c/builtins Linked here; links to this page; shared tags: #builtins, #c, #prog
- tuts/c/stdlib/stdatomic Linked here; shared tags: #c, #prog
- tuts/c/builtins/__FILE__ shared tags: #builtins, #c, #prog, #tier
- tuts/c/builtins/__func__ shared tags: #builtins, #c, #prog, #tier
- tuts/c/builtins/__LINE__ shared tags: #builtins, #c, #prog, #tier
- tuts/c/builtins/__STDC_VERSION__ shared tags: #builtins, #c, #prog, #tier
- tuts/c/builtins/_Alignof shared tags: #builtins, #c, #prog, #tier
- tuts/c/builtins/_Generic shared tags: #builtins, #c, #prog, #tier