1 .\" Copyright (c) 2016 The FreeBSD Foundation, Inc.
3 .\" This documentation was written by
4 .\" Konstantin Belousov <kib@FreeBSD.org> under sponsorship
5 .\" from the FreeBSD Foundation.
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
10 .\" 1. Redistributions of source code must retain the above copyright
11 .\" notice, this list of conditions and the following disclaimer.
12 .\" 2. Redistributions in binary form must reproduce the above copyright
13 .\" notice, this list of conditions and the following disclaimer in the
14 .\" documentation and/or other materials provided with the distribution.
16 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
20 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 .Nd create new thread of execution
39 .Fn thr_new "struct thr_param *param" "int param_size"
42 This function is intended for implementing threading.
43 Normal applications should call
50 system call creates a new kernel-scheduled thread of execution in the context
51 of the current process.
52 The newly created thread shares all attributes of the process with the
53 existing kernel-scheduled threads in the process, but has private processor
55 The machine context for the new thread is copied from the creating thread's
56 context, including coprocessor state.
57 FPU state and specific machine registers are excluded from the copy.
58 These are set according to ABI requirements and syscall parameters.
59 The FPU state for the new thread is reinitialized to clean.
63 structure supplies parameters affecting the thread creation.
64 The structure is defined in the
69 void (*start_func)(void *);
81 and contains the following fields:
82 .Bl -tag -width ".Va parent_tid"
84 Pointer to the thread entry function.
85 The kernel arranges for the new thread to start executing the function
86 upon the first return to userspace.
88 Opaque argument supplied to the entry function.
91 The stack must be allocated by the caller.
92 On some architectures, the ABI might require that the system put information
93 on the stack to ensure the execution environment for
99 The value of TLS base is loaded into the ABI-defined machine register
100 in the new thread context.
104 Address to store the new thread identifier, for the child's use.
106 Address to store the new thread identifier, for the parent's use.
112 are provided, with the intent that
114 is used by the new thread to get its thread identifier without
119 is used by the thread creator.
120 The latter is separate from
122 because the new thread might exit and free its thread data before the parent
123 has a chance to execute far enough to access it.
125 Thread creation flags.
128 member may specify the following flags:
129 .Bl -tag -width ".Dv THR_SYSTEM_SCOPE"
131 Create the new thread in the suspended state.
132 The flag is not currently implemented.
133 .It Dv THR_SYSTEM_SCOPE
134 Create the system scope thread.
135 The flag is not currently implemented.
138 Real-time scheduling priority for the new thread.
141 to inherit the priority from the
147 argument should be set to the size of the
151 After the first successful creation of an additional thread,
152 the process is marked by the kernel as multi-threaded.
155 flag is set in the process'
159 output), and several operations are executed in multi-threaded mode.
162 system call terminates all threads but the calling one on successful
167 will return zero, otherwise \-1 is returned, and
169 is set to indicate the error.
173 operation returns the following errors:
175 .\" When changing this list, consider updating share/man/man3/pthread_create.3,
176 .\" since that function can return any of these errors.
178 The memory pointed to by the
180 argument is not valid.
182 The memory pointed to by the
185 .Fa child_tid , parent_tid
188 arguments is not valid.
190 The specified stack base is invalid, or the kernel was unable to put required
191 initial data on the stack.
195 argument specifies a negative value, or the value is greater than the
198 size the kernel can interpret.
204 and specifies invalid scheduling parameters.
206 The specified TLS base is invalid.
208 The caller does not have permission to set the scheduling parameters or
211 Creation of the new thread would exceed the
214 .Xr rctl_get_racct 2 .
216 Creation of the new thread would exceed the
217 .Dv kern.threads.max_threads_per_proc
221 There was not enough kernel memory to allocate the new thread structures.
227 .Xr rctl_get_racct 2 ,
237 system call is non-standard and is used by the
246 system call first appeared in