Starts proc as a new fiber on the current scheduler; it first runs when the caller blocks or
yields. It gets a copy of the caller's context (with temporary storage of its own) and
data is copied for it.
Starts proc as a new fiber on the current scheduler and returns its handle. It first runs when the calling fiber blocks or
yields, and not at all if the scheduler ends first. The new fiber starts with a copy of the caller's context and temporary
storage of its own. Fibers share one OS thread, so they can use shared data without locks as long as they do not block in
the middle of updating it.
Io :: #import "Extensions/Io";
main :: () {
Io.io_run(() {
results := Io.make_channel(int, 1);
defer Io.free_channel(results);
Io.spawn((out: *Io.Channel(int)) { Io.send(out, 42); }, results);
value, error := Io.recv(results); // waits for the spawned fiber
assert(error == .NONE && value == 42);
});
}Doesn't run in the browser (skipped on wasm).
spawn :: (proc: $P) -> Fiber_Handle
Starts proc as a new fiber on the current scheduler; it first runs when the caller blocks or
yields. It gets a copy of the caller's context (with temporary storage of its own) and
data is copied for it.
Starts proc as a new fiber on the current scheduler and returns its handle. It first runs when the calling fiber blocks or
yields, and not at all if the scheduler ends first. The new fiber starts with a copy of the caller's context and temporary
storage of its own. Fibers share one OS thread, so they can use shared data without locks as long as they do not block in
the middle of updating it.
Parameters
- proc: $P
Returns
Io :: #import "Extensions/Io";
main :: () {
Io.io_run(() {
results := Io.make_channel(int, 1);
defer Io.free_channel(results);
Io.spawn((out: *Io.Channel(int)) { Io.send(out, 42); }, results);
value, error := Io.recv(results); // waits for the spawned fiber
assert(error == .NONE && value == 42);
});
}Doesn't run in the browser (skipped on wasm).
spawn :: (proc: $P, data: $T) -> Fiber_Handle
The spawn for a procedure that takes one argument: data is copied for the new fiber, so a pointer in it must stay valid
until the fiber is done with it.
Parameters
- proc: $P
- data: $T