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.
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
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