Std.Sync

import Std.Sync

Source


Types


Atomic

type Atomic t =
    value: t

source


Atomic.load

Atomic.load (a: ref Atomic t): t

source


Atomic.store

Atomic.store (a: ref Atomic t) (value: t): Unit

source


Atomic.swap

Atomic.swap (a: ref Atomic t) (value: t): t

Replace the value, returning the previous one.

source


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.

source


Atomic.fetch_add

Atomic.fetch_add (a: ref Atomic t) (delta: t): t

source


Atomic.fetch_sub

Atomic.fetch_sub (a: ref Atomic t) (delta: t): t

source


Atomic.fetch_and

Atomic.fetch_and (a: ref Atomic t) (mask: t): t

source


Atomic.fetch_or

Atomic.fetch_or (a: ref Atomic t) (mask: t): t

source


Atomic.fetch_xor

Atomic.fetch_xor (a: ref Atomic t) (mask: t): t

source


Mutex

type Mutex t =
    handle: VoidPtr
    value: t

source


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

source


Condvar

type Condvar =
    raw: VoidPtr

source


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

source


Condvar.signal

Condvar.signal (c: ref Condvar): Unit

Unblock one thread waiting on this condvar

source


Condvar.broadcast

Condvar.broadcast (c: ref Condvar): Unit

Unblock all threads waiting on this condvar

source


Thread

type Thread a =
    handle: VoidPtr

source


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.

source


Thread.join

Thread.join (t: Thread a): a

Block until the thread finishes and return its result.

source


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.

source


Arc

type Arc t =
    ptr: Ptr (ArcInner t)

source


Arc.as_ref

Arc.as_ref (a: imm Arc t): imm t

source


Implicits


Show Implicits

drop_mutex

impl drop_mutex {_: Drop t e}: Drop (Mutex t) e

source


clone_arc

impl clone_arc: Clone (Arc t)

source


drop_arc

impl drop_arc {_: Drop t e}: Drop (Arc t) e

source