THR_NEW(2) | System Calls Manual | THR_NEW(2) |
thr_new
— create
new thread of execution
Standard C Library (libc, -lc)
#include
<sys/thr.h>
int
thr_new
(struct
thr_param *param, int
param_size);
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. 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. These are set according to ABI requirements and syscall
parameters. The FPU state for the new thread is reinitialized to clean.
The param structure supplies parameters
affecting the thread creation. The structure is 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; };
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.
THR_SUSPENDED
THR_SYSTEM_SCOPE
NULL
to 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, the
P_HADTHREADS
flag is set in the process'
p_flag
(visible in the ps(1)
output), and several operations are executed in multi-threaded mode. For
instance, the execve(2) system call terminates all threads
but the calling one on successful execution.
If successful, thr_new
() will return zero,
otherwise -1 is returned, and errno is set to indicate
the error.
The thr_new
() operation returns the
following errors:
EFAULT
]EFAULT
]EFAULT
]EINVAL
]EINVAL
]NULL
and specifies invalid scheduling parameters.EINVAL
]EPERM
]EPROCLIM
]RACCT_NTHR
limit, see
racct(2).EPROCLIM
]kern.threads.max_threads_per_proc
sysctl(2) limit.ENOMEM
]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)
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.
June 2, 2016 | Debian |