Synchronization primitives - atomic operations, mutex, and reference counting.
All functions are backed by the Rust runtime.
An integer that can be safely read and modified from multiple threads.
Creates a new atomic integer with the given initial value.
Atomically loads and returns the current value.
Atomically stores val.
Atomically adds val and returns the previous value.
Atomically subtracts val and returns the previous value.
Atomically swaps the value with val and returns the previous value.
A mutual exclusion primitive for protecting shared data.
Creates a new mutex.
Locks the mutex. Blocks if already locked by another thread.
Unlocks the mutex.
A thread-safe reference-counted pointer for sharing data across threads.
Creates a new Arc with the given initial value and reference count 1.
Increments the reference count and returns a new handle to the same data.
Decrements the reference count. Frees the data when the count reaches zero.
load std.sync
# Atomic integer
let counter = sync.atomic_int(0)
let prev = sync.atomic_add(counter, 1)
# Mutex
let m = sync.new_mutex()
sync.mutex_lock(m)
# critical section
sync.mutex_unlock(m)
# Arc
let shared = sync.arc_new("data")
let c2 = sync.arc_clone(shared)
sync.arc_drop(shared)
sync.arc_drop(c2)