import Std.Sync
Types
Atomic
type Atomic t =
value: t
Atomic.load
Atomic.load (a: ref Atomic t): t
Atomic.store
Atomic.store (a: ref Atomic t) (value: t): Unit
Atomic.swap
Atomic.swap (a: ref Atomic t) (value: t): t
Replace the value, returning the previous one.
Atomic.compare_and_swap
Atomic.compare_and_swap (a: ref Atomic t) (current: t) (desired: t): t
If the current value equals current, replace it with desired.
Returns the previous value.
Atomic.fetch_add
Atomic.fetch_add (a: ref Atomic t) (delta: t): t
Atomic.fetch_sub
Atomic.fetch_sub (a: ref Atomic t) (delta: t): t
Atomic.fetch_and
Atomic.fetch_and (a: ref Atomic t) (mask: t): t
Atomic.fetch_or
Atomic.fetch_or (a: ref Atomic t) (mask: t): t
Atomic.fetch_xor
Atomic.fetch_xor (a: ref Atomic t) (mask: t): t
Mutex
type Mutex t =
handle: VoidPtr
value: t
Mutex.with_lock
Mutex.with_lock (m: ref Mutex t) (f: fn (mut t) [_] -> r): r
Acquires the lock, blocking until it can be acquired, then runs f, then releases the
lock, returning the result of f.
This may deadlock
Condvar
type Condvar =
raw: VoidPtr
Condvar.wait
Condvar.wait (c: ref Condvar) (m: ref Mutex t): Unit
Atomically release m’s lock and block until signalled, then re-acquire it. Must be
called while holding m’s lock (i.e. from within a Mutex.with_lock body that also
captured m).
TODO: Add MutexGuard and require that instead of a Mutex
Condvar.signal
Condvar.signal (c: ref Condvar): Unit
Unblock one thread waiting on this condvar
Condvar.broadcast
Condvar.broadcast (c: ref Condvar): Unit
Unblock all threads waiting on this condvar
Thread
type Thread a =
handle: VoidPtr
Thread.spawn
Thread.spawn (f: fn Unit [e] -> a is pure): Thread a
Spawn a new OS thread running f. The returned thread must be joined or detached.
Thread.join
Thread.join (t: Thread a): a
Block until the thread finishes and return its result.
Thread.detach
Thread.detach (t: Thread a): Unit
Detach the thread so its resources are reclaimed automatically on exit.
The result value is leaked; use join if you need it.
Arc
type Arc t =
ptr: Ptr (ArcInner t)
Arc.as_ref
Arc.as_ref (a: imm Arc t): imm t