Startseite › Sprach-Frontends › C Frontend › Übersicht Hilfe zum PBXB64-Compiler

PBXB64 - C11 Atomics

PBXB64 implements the scalar atomic types and operations from <stdatomic.h>. Atomic operations are lowered to seq_cst helper calls in the embedded c_hlib runtime, so the generated code is thread-safe without requiring special backend atomic instruction support.

Kategorie: Übersicht

Beschreibung

PBXB64 implements the scalar atomic types and operations from <stdatomic.h>. Atomic operations are lowered to seq_cst helper calls in the embedded c_hlib runtime, so the generated code is thread-safe without requiring special backend atomic instruction support.

Supported Types

atomic_bool, atomic_char, atomic_schar, atomic_uchar,
atomic_short, atomic_ushort, atomic_int, atomic_uint,
atomic_long, atomic_ulong, atomic_llong, atomic_ullong,
atomic_intptr_t, atomic_uintptr_t, atomic_size_t,
atomic_ptrdiff_t, atomic_intmax_t, atomic_uintmax_t

Supported Operations

MacroNotes
atomic_load, atomic_load_explicitRead value
atomic_store, atomic_store_explicitWrite value
atomic_exchange, atomic_exchange_explicitSwap value
atomic_fetch_add, atomic_fetch_subAdd/subtract and return old value
atomic_fetch_or, atomic_fetch_and, atomic_fetch_xorBitwise ops and return old value
atomic_compare_exchange_strong, atomic_compare_exchange_weakCAS (weak is strong)
atomic_flag_test_and_set, atomic_flag_clearAtomic flag ops

Memory Orders

All six memory_order constants are accepted. The current runtime always uses seq_cst behavior regardless of the requested order.

Limitation: Pointer-sized atomics are supported; atomic pointers (_Atomic void*) and atomic floats are not yet implemented.

Back to C Language Reference

Beispiel

#include <stdatomic.h>

static atomic_int counter;

int main(void) {
    atomic_init(&counter, 0);
    atomic_fetch_add(&counter, 1);
    return atomic_load(&counter) == 1 ? 0 : 1;
}