xref: /openbsd-src/share/man/man9/thread_fork.9 (revision bb822012021656e5cd311b5bcf795a7ff507d448)
1*bb822012Sguenther.\"	$OpenBSD: thread_fork.9,v 1.2 2017/02/15 03:33:13 guenther Exp $
279a514fcSguenther.\"	$NetBSD: fork1.9,v 1.3 1999/03/16 00:40:47 garbled Exp $
379a514fcSguenther.\"
479a514fcSguenther.\" Copyright (c) 1998 The NetBSD Foundation, Inc.
579a514fcSguenther.\" All rights reserved.
679a514fcSguenther.\"
779a514fcSguenther.\" This code is derived from software contributed to The NetBSD Foundation
879a514fcSguenther.\" by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
979a514fcSguenther.\" NASA Ames Research Center.
1079a514fcSguenther.\"
1179a514fcSguenther.\" Redistribution and use in source and binary forms, with or without
1279a514fcSguenther.\" modification, are permitted provided that the following conditions
1379a514fcSguenther.\" are met:
1479a514fcSguenther.\" 1. Redistributions of source code must retain the above copyright
1579a514fcSguenther.\"    notice, this list of conditions and the following disclaimer.
1679a514fcSguenther.\" 2. Redistributions in binary form must reproduce the above copyright
1779a514fcSguenther.\"    notice, this list of conditions and the following disclaimer in the
1879a514fcSguenther.\"    documentation and/or other materials provided with the distribution.
1979a514fcSguenther.\"
2079a514fcSguenther.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2179a514fcSguenther.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2279a514fcSguenther.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2379a514fcSguenther.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2479a514fcSguenther.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2579a514fcSguenther.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2679a514fcSguenther.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2779a514fcSguenther.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2879a514fcSguenther.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2979a514fcSguenther.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3079a514fcSguenther.\" POSSIBILITY OF SUCH DAMAGE.
3179a514fcSguenther.\"
32*bb822012Sguenther.Dd $Mdocdate: February 15 2017 $
3379a514fcSguenther.Dt THREAD_FORK 9
3479a514fcSguenther.Os
3579a514fcSguenther.Sh NAME
3679a514fcSguenther.Nm thread_fork
3779a514fcSguenther.Nd create a new thread inside a process
3879a514fcSguenther.Sh SYNOPSIS
3979a514fcSguenther.In sys/types.h
4079a514fcSguenther.In sys/proc.h
4179a514fcSguenther.Ft int
4279a514fcSguenther.Fo thread_fork
4379a514fcSguenther.Fa "struct proc *p1"
4479a514fcSguenther.Fa "void *stack"
4579a514fcSguenther.Fa "void *tcb"
4679a514fcSguenther.Fa "pid_t *tidptr"
4779a514fcSguenther.Fa "register_t *retval"
4879a514fcSguenther.Fc
4979a514fcSguenther.Sh DESCRIPTION
5079a514fcSguenther.Fn thread_fork
5179a514fcSguenthercreates a new thread out of
5279a514fcSguenther.Ar p1 ,
5379a514fcSguentherwhich should be the current thread.
5479a514fcSguentherThis function is used to implement the
5579a514fcSguenther.Xr __tfork 3
5679a514fcSguenthersystem call.
5779a514fcSguenther.Pp
5879a514fcSguenther.Fa stack ,
5979a514fcSguentherwhich must not be
6079a514fcSguenther.Dv NULL ,
6179a514fcSguentherwill be used as the initial value of the new thread's stack pointer.
6279a514fcSguenther.Pp
6379a514fcSguentherIf
64*bb822012Sguenther.Fa tcb
6579a514fcSguentheris not
6679a514fcSguenther.Dv NULL ,
6779a514fcSguentherit will be used as the initial address of the new thread's TCB
6879a514fcSguenther(thread control block).
6979a514fcSguenther.Pp
7079a514fcSguentherIf
7179a514fcSguenther.Fa tidptr
7279a514fcSguentheris not
7379a514fcSguenther.Dv NULL ,
7479a514fcSguentherthe TID of the new thread will be copied out there on success.
7579a514fcSguentherThis is guaranteed to be done before the new thread is started.
7679a514fcSguenther.Pp
77*bb822012SguentherOn successful completion the TID of the new thread will be stored in
78*bb822012Sguenther.Fa *retval .
7979a514fcSguenther.Sh RETURN VALUES
8079a514fcSguentherUpon successful completion of the operation,
8179a514fcSguenther.Fn thread_fork
8279a514fcSguentherreturns 0.
8379a514fcSguentherOtherwise, the following error values are returned:
8479a514fcSguenther.Bl -tag -width [EAGAIN]
8579a514fcSguenther.It Bq Er EAGAIN
8679a514fcSguentherThe system limit on the total number of threads would be exceeded.
8779a514fcSguenther.It Bq Er ENOMEM
8879a514fcSguentherThere is insufficient swap space for the new thread.
8979a514fcSguenther.It Bq Er EINVAL
9079a514fcSguentherThe
9179a514fcSguenther.Fa stack
9279a514fcSguentherargument was
9379a514fcSguenther.Dv NULL .
9479a514fcSguenther.El
9579a514fcSguenther.Sh SEE ALSO
96*bb822012Sguenther.Xr __get_tcb 2 ,
9779a514fcSguenther.Xr fork 2 ,
9879a514fcSguenther.Xr __tfork 3 ,
9979a514fcSguenther.Xr tfind 9
10079a514fcSguenther.Sh HISTORY
10179a514fcSguentherThe
10279a514fcSguenther.Fn thread_fork
10379a514fcSguentherfunction
10479a514fcSguentherappeared in
10579a514fcSguenther.Ox 6.1 .
106