On this page
  1. _Atomic
  2. Availability
  3. Syntax & Overview
  4. Notes & Pitfalls
  5. Example

_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

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