Skip to content

@threads

Import this module with import @threads.

Thread lifecycle management. Compiler-only feature; requires POSIX threads.

Function Signature Description
spawn (fn func()) -> Thread Spawn a new thread running fn
spawn_arg (fn func(i64), arg i64) -> Thread Spawn a new thread running fn, passing arg as its i64 parameter
join (t Thread) Wait for a thread to finish
detach (t Thread) Release ownership; the thread runs independently. After detach the handle must not be joined or queried
is_alive (t Thread) -> bool True while the thread’s body has not returned. Not valid after detach or join
get_id () -> i64 Get the current thread’s ID
yield () Hint the scheduler to run another runnable thread
sleep (ms i64) Sleep the current thread for ms milliseconds
thread_count () -> i64 Number of live threads spawned through this module (excludes main and non-Grayscale threads)