API Reference › Sync
namespace

Sync

The advanced, opt-in tier — here be dragons. Raw building blocks for engine-level systems that pass data around: a mutex (cooperative lock), an atomic counter (get / set / add / cas) and a bounded channel (send / recv / can_recv / len). On today's single-threaded deterministic runtime these are cooperative — correct, ordered, replayable and impossible to deadlock — and exist so message-passing code reads the same now as it will when a preemptive OS-thread backend lands behind this same API. Beginners never need this; reach for Job.* / Promise.* instead. Spliced in only when a program mentions Sync.*.

Sync.mutex() -> intCreate a cooperative lock.Sync.lock(mutex) -> voidTake the lock.Sync.unlock(mutex) -> voidRelease the lock.Sync.try_lock(mutex) -> boolTake the lock only if it is free.Sync.atomic() -> intCreate an atomic counter (starts at 0).Sync.get(atomic) -> intRead the counter.Sync.set(atomic, value) -> voidStore a value in the counter.Sync.add(atomic, delta) -> intAdd to the counter; return the new value.Sync.cas(atomic, expect, next) -> boolCompare-and-set the counter.Sync.channel() -> intCreate a bounded int FIFO channel.Sync.send(channel, value) -> boolEnqueue a value (false if full).Sync.recv(channel) -> intDequeue the oldest value.Sync.can_recv(channel) -> boolIs there a value waiting?Sync.len(channel) -> intHow many values are queued.Sync.cpu_count() -> intThe machine's logical cores (1 to 64); Job.parallel_for uses one thread per core.
← All symbols