std.thread
std.thread: operating system threads (pthreads). A panic in any thread ends the program; each thread has its own error return trace.
SpawnError
pub error SpawnError { SystemResources }
The error of `spawn`: the system has no resources for another thread.
Thread
pub struct Thread {
handle: u64
pub fn join(self: Self)
}
A running thread. `join` waits for it to finish; every spawned thread is joined once.
pub fn join(self: Self)-
Waits until the thread's function has returned.
spawn
pub fn spawn(comptime T: type, f: fn(*mut T), arg: *mut T) SpawnError!Thread
Starts a thread that runs `f(arg)`, with a stack of 8 MiB (as the main thread has on macOS and Linux). `arg` must stay valid until the thread is joined, and what the thread shares with others is guarded by a `std.sync.Mutex`, sent through a `std.sync.Channel` or an `std.sync.Atomic` (an allocator is not shared: give each thread its own).
spawnWithStack
pub fn spawnWithStack(comptime T: type, f: fn(*mut T), arg: *mut T, stack: usize) SpawnError!Thread
`spawn` with a stack of at least `stack` bytes (rounded up to a multiple of 64 KiB, at least 256 KiB), for deep recursion: a tree-walking interpreter can ask for 1 GiB (`1 << 30`); the memory is reserved, and only the part that is used is taken.