Zig 0.17.0-dev (Split by item)

This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig library itself.

spawn

Spawns a new thread which executes function using args and returns a handle to the spawned thread. config can be used as hints to the platform for how to spawn and execute the function. The caller must eventually either call join() to wait for the thread to finish and free its resources or call detach() to excuse the caller from calling join() and have the thread clean up its resources on completion.

Thread.spawn
pub fn spawn(config: SpawnConfig, comptime function: anytype, args: anytype) SpawnError!Thread

File

lib/std/Thread.zig:344

Code

pub fn spawn(config: SpawnConfig, comptime function: anytype, args: anytype) SpawnError!Thread {
    if (builtin.single_threaded) {
        @compileError("Cannot spawn thread when building in single-threaded mode");
    }

    const impl = try Impl.spawn(config, function, args);
    return Thread{ .impl = impl };
}