thread¶
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 ifChannel
is empty. Returns(Index, Message)
whereIndex = 1, ..., n
.meth (Channel: thread::channel):send(Message: any): thread::channel
Adds
Message
toChannel
.Message
must be thread-safe. Blocks ifChannel
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
, usingMutex
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 callsFunction(Value₁, ..., Valueₙ)
whereValueᵢ
is the value protected byProtectedᵢ
. AllProtectedᵢ
must be protected by the samethread::mutex
.