1 .\" Copyright (c) 2016 The FreeBSD Foundation, Inc.
2 .\" All rights reserved.
4 .\" This documentation was written by
5 .\" Konstantin Belousov <kib@FreeBSD.org> under sponsorship
6 .\" from the FreeBSD Foundation.
8 .\" Redistribution and use in source and binary forms, with or without
9 .\" modification, are permitted provided that the following conditions
11 .\" 1. Redistributions of source code must retain the above copyright
12 .\" notice, this list of conditions and the following disclaimer.
13 .\" 2. Redistributions in binary form must reproduce the above copyright
14 .\" notice, this list of conditions and the following disclaimer in the
15 .\" documentation and/or other materials provided with the distribution.
17 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
18 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
21 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 .Nd create new thread of execution
42 .Fn thr_new "struct thr_param *param" "int param_size"
46 system call creates a new kernel-scheduled thread of execution in the context
47 of the current process.
48 The newly created thread shares all attributes of the process with the
49 existing kernel-scheduled threads in the process, but has private processor
51 The machine context for the new thread is copied from the creating thread's
52 context, including coprocessor state.
53 FPU state and specific machine registers are excluded from the copy.
54 These are set according to ABI requirements and syscall parameters.
55 The FPU state for the new thread is reinitialized to clean.
59 structure supplies parameters affecting the thread creation.
60 The structure is defined in the
65 void (*start_func)(void *);
77 and contains the following fields:
78 .Bl -tag -width ".Va parent_tid"
80 Pointer to the thread entry function.
81 The kernel arranges for the new thread to start executing the function
82 upon the first return to userspace.
84 Opaque argument supplied to the entry function.
87 The stack must be allocated by the caller.
88 On some architectures, the ABI might require that the system put information
89 on the stack to ensure the execution environment for
95 The value of TLS base is loaded into the ABI-defined machine register
96 in the new thread context.
100 Address to store the new thread identifier, for the child's use.
102 Address to store the new thread identifier, for the parent's use.
108 are provided, with the intent that
110 is used by the new thread to get its thread identifier without
115 is used by the thread creator.
116 The latter is separate from
118 because the new thread might exit and free its thread data before the parent
119 has a chance to execute far enough to access it.
121 Thread creation flags.
124 member may specify the following flags:
125 .Bl -tag -width ".Dv THR_SYSTEM_SCOPE"
127 Create the new thread in the suspended state.
128 The flag is not currently implemented.
129 .It Dv THR_SYSTEM_SCOPE
130 Create the system scope thread.
131 The flag is not currently implemented.
134 Real-time scheduling priority for the new thread.
137 to inherit the priority from the
143 argument should be set to the size of the
147 After the first successful creation of an additional thread,
148 the process is marked by the kernel as multi-threaded.
151 flag is set in the process'
155 output), and several operations are executed in multi-threaded mode.
158 system call terminates all threads but the calling one on successful
163 will return zero, otherwise \-1 is returned, and
165 is set to indicate the error.
169 operation returns the following errors:
172 The memory pointed to by the
174 argument is not valid.
176 The memory pointed to by the
179 .Fa child_tid , parent_tid
182 arguments is not valid.
184 Specified stack base is invalid, or the kernel was unable to put required
185 initial data on the stack.
189 argument specifies a negative value, or the value is greater than the
192 size the kernel can interpret.
198 and specifies invalid scheduling parameters.
200 The specified TLS base is invalid.
202 Creation of the new thread would exceed the
207 Creation of the new thread would exceed the
208 .Dv kern.threads.max_threads_per_proc
212 No kernel memory to allocate for the new thread structures.
227 system call is non-standard and is used by the