thread¶
fun mlthreadport(Arg₁: any)TBD
meth (Args...: any):thread(Fn: function, Arg₃: any): threadCreates a new thread and calls
Fn(Args...)in the new thread. All arguments must be thread-safe.fun thread::sleep(Duration: number): nilCauses the current thread to sleep for
Durationmicroseconds.type threadA thread.
meth thread()TBD
meth (Thread: thread):join: anyWaits until the thread
Threadcompletes and returns its result.type thread::channelA channel for thread communication.
fun thread::channel(Capacity: integer): thread::channelCreates 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 ifChannelis empty. Returns(Index, Message)whereIndex = 1, ..., n.meth (Channel: thread::channel):send(Message: any): thread::channelAdds
MessagetoChannel.Messagemust be thread-safe. Blocks ifChannelis currently full.type thread::conditionA condition.
fun thread::condition(): thread::conditionCreates a new condition.
meth (Condition: thread::condition):broadcast: thread::conditionSignals all threads waiting on
Condition.meth (Condition: thread::condition):signal: thread::conditionSignals a single thread waiting on
Condition.meth (Condition: thread::condition):wait(Mutex: thread::mutex): thread::conditionWaits for a signal on
Condition, usingMutexfor synchronization.type thread::mutexA mutex.
fun thread::mutex(): thread::mutexCreates a new mutex.
meth (Mutex: thread::mutex):lock: thread::mutexLocks
Mutex.meth (Mutex: thread::mutex):protect(Value: any): thread::protectedCreates a thread-safe (protected) wrapper for
Value.meth (Mutex: thread::mutex):unlock: thread::mutexUnlocks
Mutex.type thread::port < functionTBD
type thread::protectedA thread-safe (protected) wrapper for another value.
meth (Protected₁: thread::protected):use(: thread::protected, ..., Function: function): anyLocks
Protected₁:mutex, then callsFunction(Value₁, ..., Valueₙ)whereValueᵢis the value protected byProtectedᵢ. AllProtectedᵢmust be protected by the samethread::mutex.