Module worker

worker

Thread pool with per-core thread affinity and round-robin task distribution.

Each task is pinned to a worker thread (no work stealing). Each worker thread has its own GC heap and async IO event loop.

Functions

spawn function
fn(cb : Impl(Fn(using(io : IO)) -> unit, Send)) -> unit

Spawn a task on the thread pool. Returns immediately; the task runs in the background. Tasks are distributed round-robin to worker threads.

Parameters

NameTypeNotes
cbImpl(Fn(using(io : IO)) -> unit, Send)

Returns: unit

get_num_threads function
fn() -> usize

Get the number of worker threads in the pool. Defaults to the number of hardware threads (CPU cores).

Returns: usize

set_num_threads function
fn(num : usize) -> unit

Set the number of worker threads in the pool. Must be called before the first spawn to take effect.

Parameters

NameTypeNotes
numusize

Returns: unit