THR_NEW(2)
β¨ THR_NEW β¨ β create new thread of execution π«
okay bestie, gather round, we're in the THR_NEW(2) page from the System Calls Manual and it's giving kernel internals energy π§
π LIBRARY
Standard C Library (libc, -lc) π«Ά
πΈ SYNOPSIS
#include <sys/thr.h>
int
thr_new(struct thr_param *param, int param_size);
π DESCRIPTION
so like, this function is intended for implementing threading β it's the plumbing, not the pretty faucet. Normal applications should call pthread_create(3) instead, fr fr. π
The thr_new() system call creates a new kernel-scheduled thread of execution in the context of the current process. The newly created thread shares all attributes of the process with the existing kernel-scheduled threads in the process, but has private processor execution state. no cap. The machine context for the new thread is copied from the creating thread's context, including coprocessor state. FPU state and specific machine registers are excluded from the copy β those get set according to ABI requirements and syscall parameters. And the FPU state for the new thread is reinitialized to clean β¨
The param structure supplies parameters affecting the thread creation. It's defined in the <sys/thr.h> header as follows:
struct thr_param {
void (*start_func)(void *);
void *arg;
char *stack_base;
size_t stack_size;
char *tls_base;
size_t tls_size;
long *child_tid;
long *parent_tid;
int flags;
struct rtprio *rtp;
};
and it contains the following fields, bestie:
start_funcβ Pointer to the thread entry function. The kernel arranges for the new thread to start executing the function upon the first return to userspace. it's literally the main character's first scene π¬argβ Opaque argument supplied to the entry function.stack_baseβ Stack base address. The stack must be allocated by the caller. On some architectures, the ABI might require that the system put information on the stack to ensure the execution environment forstart_func. πstack_sizeβ Stack size.tls_baseβ TLS base address. The value of TLS base is loaded into the ABI-defined machine register in the new thread context.tls_sizeβ TLS size.child_tidβ Address to store the new thread identifier, for the child's use.parent_tidβ Address to store the new thread identifier, for the parent's use.
Both child_tid and parent_tid are provided, with the intent that child_tid is used by the new thread to get its thread identifier without issuing the thr_self(2) syscall, while parent_tid is used by the thread creator. The latter is separate from child_tid because the new thread might exit and free its thread data before the parent has a chance to execute far enough to access it. π (rip to the parent, honestly)
flagsβ Thread creation flags. Theflagsmember may specify the following flags:THR_SUSPENDEDβ Create the new thread in the suspended state. The flag is not currently implemented. π§THR_SYSTEM_SCOPEβ Create the system scope thread. The flag is not currently implemented. π§
rtpβ Real-time scheduling priority for the new thread. May beNULLto inherit the priority from the creating thread.
The param_size argument should be set to the size of the param structure.
β After the first successful creation of an additional thread, the process is marked by the kernel as multi-threaded. In particular, theP_HADTHREADSflag is set in the process'p_flag(visible in theps(1)output), and several operations are executed in multi-threaded mode. For instance, theexecve(2)system call terminates all threads but the calling one on successful execution. iconic behaviour honestly π
π«Ά RETURN VALUES
If successful, thr_new() will return zero, otherwise -1 is returned, and errno is set to indicate the error. classic. π
π ERRORS
The thr_new() operation returns the following errors:
[EFAULT]β The memory pointed to by theparamargument is not valid.[EFAULT]β The memory pointed to by theparamstructurechild_tid,parent_tidorrtparguments is not valid.[EFAULT]β The specified stack base is invalid, or the kernel was unable to put required initial data on the stack.[EINVAL]β Theparam_sizeargument specifies a negative value, or the value is greater than the largeststruct paramsize the kernel can interpret.[EINVAL]β Thertpmember is notNULLand specifies invalid scheduling parameters.[EINVAL]β The specified TLS base is invalid.[EPERM]β The caller does not have permission to set the scheduling parameters or scheduling policy.[EPROCLIM]β Creation of the new thread would exceed theRACCT_NTHRlimit, seeracct(2).[EPROCLIM]β Creation of the new thread would exceed thekern.threads.max_threads_per_procsysctl(2)limit.[ENOMEM]β There was not enough kernel memory to allocate the new thread structures.
π SEE ALSO
ps(1), execve(2), racct(2), thr_exit(2), thr_kill(2), thr_kill2(2), thr_self(2), thr_set_name(2), _umtx_op(2), pthread_create(3)
π STANDARDS
The thr_new() system call is non-standard and is used by the 1:1 Threading Library (libthr, -lthr) to implement IEEE Std 1003.1-2001 ("POSIX.1") pthread(3) functionality. periodt. π
okay that's the whole page bestie, go forth and spawn threads responsibly π¦
this lil masterpiece is from Debian, dated June 2, 2016 β mwah, sending love to whoever wrote it, you ate π β¨
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 2016 The FreeBSD Foundation, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms