1.\" $OpenBSD: thread_fork.9,v 1.2 2017/02/15 03:33:13 guenther Exp $ 2.\" $NetBSD: fork1.9,v 1.3 1999/03/16 00:40:47 garbled Exp $ 3.\" 4.\" Copyright (c) 1998 The NetBSD Foundation, Inc. 5.\" All rights reserved. 6.\" 7.\" This code is derived from software contributed to The NetBSD Foundation 8.\" by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 9.\" NASA Ames Research Center. 10.\" 11.\" Redistribution and use in source and binary forms, with or without 12.\" modification, are permitted provided that the following conditions 13.\" are met: 14.\" 1. Redistributions of source code must retain the above copyright 15.\" notice, this list of conditions and the following disclaimer. 16.\" 2. Redistributions in binary form must reproduce the above copyright 17.\" notice, this list of conditions and the following disclaimer in the 18.\" documentation and/or other materials provided with the distribution. 19.\" 20.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 21.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 24.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30.\" POSSIBILITY OF SUCH DAMAGE. 31.\" 32.Dd $Mdocdate: February 15 2017 $ 33.Dt THREAD_FORK 9 34.Os 35.Sh NAME 36.Nm thread_fork 37.Nd create a new thread inside a process 38.Sh SYNOPSIS 39.In sys/types.h 40.In sys/proc.h 41.Ft int 42.Fo thread_fork 43.Fa "struct proc *p1" 44.Fa "void *stack" 45.Fa "void *tcb" 46.Fa "pid_t *tidptr" 47.Fa "register_t *retval" 48.Fc 49.Sh DESCRIPTION 50.Fn thread_fork 51creates a new thread out of 52.Ar p1 , 53which should be the current thread. 54This function is used to implement the 55.Xr __tfork 3 56system call. 57.Pp 58.Fa stack , 59which must not be 60.Dv NULL , 61will be used as the initial value of the new thread's stack pointer. 62.Pp 63If 64.Fa tcb 65is not 66.Dv NULL , 67it will be used as the initial address of the new thread's TCB 68(thread control block). 69.Pp 70If 71.Fa tidptr 72is not 73.Dv NULL , 74the TID of the new thread will be copied out there on success. 75This is guaranteed to be done before the new thread is started. 76.Pp 77On successful completion the TID of the new thread will be stored in 78.Fa *retval . 79.Sh RETURN VALUES 80Upon successful completion of the operation, 81.Fn thread_fork 82returns 0. 83Otherwise, the following error values are returned: 84.Bl -tag -width [EAGAIN] 85.It Bq Er EAGAIN 86The system limit on the total number of threads would be exceeded. 87.It Bq Er ENOMEM 88There is insufficient swap space for the new thread. 89.It Bq Er EINVAL 90The 91.Fa stack 92argument was 93.Dv NULL . 94.El 95.Sh SEE ALSO 96.Xr __get_tcb 2 , 97.Xr fork 2 , 98.Xr __tfork 3 , 99.Xr tfind 9 100.Sh HISTORY 101The 102.Fn thread_fork 103function 104appeared in 105.Ox 6.1 . 106