Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
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 standard library. Public Function

spawn

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

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.

Params

Errors

ThreadQuotaExceeded

A system-imposed limit on the number of threads was encountered. There are a number of limits that may trigger this error:

  • the RLIMIT_NPROC soft resource limit (set via setrlimit(2)), which limits the number of processes and threads for a real user ID, was reached;
  • the kernel's system-wide limit on the number of processes and threads, /proc/sys/kernel/threads-max, was reached (see proc(5));
  • the maximum number of PIDs, /proc/sys/kernel/pid_max, was reached (see proc(5)); or
  • the PID limit (pids.max) imposed by the cgroup "process num‐ ber" (PIDs) controller was reached.
SystemResources

The kernel cannot allocate sufficient memory to allocate a task structure for the child, or to copy those parts of the caller's context that need to be copied.

OutOfMemory

Not enough userland memory to spawn the thread.

LockedMemoryLimitExceeded

mlockall is enabled, and the memory needed to spawn the thread would exceed the limit.

Unexpected

File

Thread.zig:344
344
345
346
347
348
349
350
351
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 };
}