std1.0.0-beta-7 SafeC docs

Module atomic

#include <std/atomic.h> source

Atomics (C11 <stdatomic.h>) Lock-free operations on shared integers and pointers. All functions require unsafe{} at the call site only when storing results in raw pointers; the operations themselves are memory-safe.

Structs

AtomicIntAn int / long long every access to which is atomic: Sync, so threads may share one through a mutable reference ('&static AtomicInt', or a local lent to spawn_scoped threads) where a plain int would race. static struct AtomicInt hits; // zero-initialized hits.fetch_add(1);
AtomicLong

Functions

atomic_load_int
atomic_store_intAtomically store val into *addr.
atomic_fetch_add_intAtomically add delta to *addr; return the old value.
atomic_fetch_sub_intAtomically subtract delta from *addr; return the old value.
atomic_fetch_and_intAtomically AND *addr with mask; return the old value.
atomic_fetch_or_intAtomically OR *addr with mask; return the old value.
atomic_fetch_xor_intAtomically XOR *addr with mask; return the old value.
atomic_exchange_intAtomically exchange *addr with val; return the old value.
atomic_cas_intCAS: if *addr == expected, store desired and return 1; else update *expected to the current value and return 0.
atomic_load_ll
atomic_store_ll
atomic_fetch_add_ll
atomic_fetch_sub_ll
atomic_exchange_ll
atomic_cas_ll
atomic_thread_fenceFull sequential-consistency fence.