Scripting & runtime · atomics
Share small scalar state without a mutex.
atomic<int> and atomic<bool> are transferable, sequentially consistent scalar references for threads and async functions.
count := atomic<int>(0)
ready := atomic<bool>(false)
count++
count += 4
ready = true
print(count)
if(ready) { print("ready") } atomic<int> stores a signed 64-bit integer. It supports scalar assignment, ++, --, +=, -=, &=, |=, ^=, and %=. atomic<bool> supports boolean assignment and reads naturally in expressions. Arithmetic such as *= or /= is not an atomic operator; use a supported method or a mutex-protected invariant.
Explicit operations
old := count.load()
count.store(10)
previous := count.exchange(20)
changed := count.compare_exchange(20, 21)
before_add := count.fetch_add(5)
before_sub := count.fetch_sub(2) Both atomic types provide load(), store(value), exchange(value), and compare_exchange(expected, desired). Integer atomics additionally provide fetch_add() and fetch_sub(). Nift intentionally exposes sequential consistency rather than C++ memory-order controls.
Assignment updates the shared atomic; copying or passing the handle preserves alias identity. This is deliberately different from ordinary values, which are isolated across workers.