Module atomic
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
| AtomicInt | An 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_int | Atomically store val into *addr. |
| atomic_fetch_add_int | Atomically add delta to *addr; return the old value. |
| atomic_fetch_sub_int | Atomically subtract delta from *addr; return the old value. |
| atomic_fetch_and_int | Atomically AND *addr with mask; return the old value. |
| atomic_fetch_or_int | Atomically OR *addr with mask; return the old value. |
| atomic_fetch_xor_int | Atomically XOR *addr with mask; return the old value. |
| atomic_exchange_int | Atomically exchange *addr with val; return the old value. |
| atomic_cas_int | CAS: 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_fence | Full sequential-consistency fence. |