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.
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.
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
| Macro | Notes |
|---|---|
atomic_load, atomic_load_explicit | Read value |
atomic_store, atomic_store_explicit | Write value |
atomic_exchange, atomic_exchange_explicit | Swap value |
atomic_fetch_add, atomic_fetch_sub | Add/subtract and return old value |
atomic_fetch_or, atomic_fetch_and, atomic_fetch_xor | Bitwise ops and return old value |
atomic_compare_exchange_strong, atomic_compare_exchange_weak | CAS (weak is strong) |
atomic_flag_test_and_set, atomic_flag_clear | Atomic flag ops |
All six memory_order constants are accepted. The current runtime always uses seq_cst behavior regardless of the requested order.
_Atomic void*) and atomic floats are not yet implemented.#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;
}