std.concurrent
Concurrency helper module.
yaoxiang
use std.concurrentThis module depends on operating system threads and is not exported on the
wasm32target.
Function List
| Function | Signature |
|---|---|
sleep | (millis: Int) -> Void |
thread_id | () -> String |
yield_now | () -> Void |
Functions
sleep
yaoxiang
sleep: (millis: Int) -> VoidBlocks the current thread for the specified number of milliseconds.
millis—— number of milliseconds to sleep; if not anIntor missing, treated as0(no error)
Unit note:
std.time.sleeptakes seconds and accepts decimals, while this function takes milliseconds.concurrent.sleep(1)sleeps for 1 millisecond, andtime.sleep(1)sleeps for 1 second.
yaoxiang
use std.concurrent
main: () -> Void = {
concurrent.sleep(0)
concurrent.sleep(1)
}thread_id
yaoxiang
thread_id: () -> StringReturns the identifier string of the current thread.
Returns: a string like ThreadId(1). The specific value varies by platform and scheduling; you should only check for its existence, not rely on its specific content or format.
yaoxiang
use std.assert
use std.concurrent
use std.string
main: () -> Void = {
tid = concurrent.thread_id()
assert(string.len(tid) > 0)
}yield_now
yaoxiang
yield_now: () -> VoidActively yields the current thread's scheduling time slice, giving other threads a chance to run.
yaoxiang
use std.concurrent
main: () -> Void = {
concurrent.yield_now()
}Related
std.time.sleep—— second-level sleep- Language Spec: Concurrency Model ——
spawnand spawn semantics
