pub fn spawn(config: SpawnConfig, comptime function: anytype, args: anytype) SpawnError!Thread config: SpawnConfigfunctionargsThreadQuotaExceededA system-imposed limit on the number of threads was encountered. There are a number of limits that may trigger this error:
SystemResourcesThe 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.
OutOfMemoryNot enough userland memory to spawn the thread.
LockedMemoryLimitExceededmlockall is enabled, and the memory needed to spawn the thread would exceed the limit.
Unexpected344
345
346
347
348
349
350
351pub 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 };
}
Spawns a new thread which executes
functionusingargsand returns a handle to the spawned thread.configcan be used as hints to the platform for how to spawn and execute thefunction. The caller must eventually either calljoin()to wait for the thread to finish and free its resources or calldetach()to excuse the caller from callingjoin()and have the thread clean up its resources on completion.