Io module

io_run_threads

procedure · 2 overloadsSource

Starts count schedulers, each on a thread of its own, runs proc as the first fiber of every one, and returns when all have finished. Fibers never move between them. With reuse_port listeners (tcp_listen(..., reuse_port = true)) each thread accepts its own connections.

count 0 means one per processor. Call it from outside any io_run.

Example
Io :: #import "Extensions/Io";
Atomics :: #import "Atomics";

started: s32;

main :: () {
    Io.io_run_threads(2, () {
        Atomics.atomic_add(*started, 1);
    });

    assert(started == 2);
}

Doesn't run in the browser (skipped on wasm).

io_run_threads :: (count: s64, proc: $P)

Starts count schedulers, each on a thread of its own, runs proc as the first fiber of every one, and returns when all have finished. Fibers never move between them. With reuse_port listeners (tcp_listen(..., reuse_port = true)) each thread accepts its own connections.

count 0 means one per processor. Call it from outside any io_run.

Parameters

count: s64
proc: $P
Example
Io :: #import "Extensions/Io";
Atomics :: #import "Atomics";

started: s32;

main :: () {
    Io.io_run_threads(2, () {
        Atomics.atomic_add(*started, 1);
    });

    assert(started == 2);
}

Doesn't run in the browser (skipped on wasm).

io_run_threads :: (count: s64, proc: $P, data: $T)

The io_run_threads for a procedure that takes one argument: data is copied for the first fiber of every scheduler.

Parameters

count: s64
proc: $P
data: $T

See also