fun thread::sleep(Duration: number): nil

Causes the current thread to sleep for Duration microseconds.

type thread

A thread.

fun thread(Args: any, ..., Fn: function): thread

Creates a new thread and calls Fn(Args...) in the new thread. All arguments must be thread-safe.

meth (Thread: thread):join: any

Waits until the thread Thread completes and returns its result.

type thread::channel

A channel for thread communication.

fun thread::channel(Capacity: integer): thread::channel

Creates a new channel with capacity Capacity.

meth (Channel₁: thread::channel):recv(: thread::channel, ...): tuple[integer, any]

Gets the next available message on any of Channel₁, ..., Channelₙ, blocking if Channel is empty. Returns (Index, Message) where Index = 1, ..., n.

meth (Channel: thread::channel):send(Message: any): thread::channel

Adds Message to Channel. Message must be thread-safe. Blocks if Channel is currently full.

type thread::condition

A condition.

fun thread::condition(): thread::condition

Creates a new condition.

meth (Condition: thread::condition):broadcast: thread::condition

Signals all threads waiting on Condition.

meth (Condition: thread::condition):signal: thread::condition

Signals a single thread waiting on Condition.

meth (Condition: thread::condition):wait(Mutex: thread::mutex): thread::condition

Waits for a signal on Condition, using Mutex for synchronization.

type thread::mutex

A mutex.

fun thread::mutex(): thread::mutex

Creates a new mutex.

meth (Mutex: thread::mutex):lock: thread::mutex

Locks Mutex.

meth (Mutex: thread::mutex):protect(Value: any): thread::protected

Creates a thread-safe (protected) wrapper for Value.

meth (Mutex: thread::mutex):unlock: thread::mutex

Unlocks Mutex.

type thread::protected

A thread-safe (protected) wrapper for another value.

meth (Protected₁: thread::protected):use(: thread::protected, ..., Function: function): any

Locks Protected₁:mutex, then calls Function(Value₁, ..., Valueₙ) where Valueᵢ is the value protected by Protectedᵢ. All Protectedᵢ must be protected by the same thread::mutex.