xref: /dflybsd-src/lib/libc/sys/lwp_create.2 (revision 25dffe656687e84d439135b2dc14d87961fc143f)
1*25dffe65SSimon Schubert.\" Copyright (c) 2007 The DragonFly Project.  All rights reserved.
2*25dffe65SSimon Schubert.\"
3*25dffe65SSimon Schubert.\" This code is derived from software contributed to The DragonFly Project
4*25dffe65SSimon Schubert.\" by Simon 'corecode' Schubert <corecode@fs.ei.tum.de>
5*25dffe65SSimon Schubert.\"
6*25dffe65SSimon Schubert.\" Redistribution and use in source and binary forms, with or without
7*25dffe65SSimon Schubert.\" modification, are permitted provided that the following conditions
8*25dffe65SSimon Schubert.\" are met:
9*25dffe65SSimon Schubert.\"
10*25dffe65SSimon Schubert.\" 1. Redistributions of source code must retain the above copyright
11*25dffe65SSimon Schubert.\"    notice, this list of conditions and the following disclaimer.
12*25dffe65SSimon Schubert.\" 2. Redistributions in binary form must reproduce the above copyright
13*25dffe65SSimon Schubert.\"    notice, this list of conditions and the following disclaimer in
14*25dffe65SSimon Schubert.\"    the documentation and/or other materials provided with the
15*25dffe65SSimon Schubert.\"    distribution.
16*25dffe65SSimon Schubert.\" 3. Neither the name of The DragonFly Project nor the names of its
17*25dffe65SSimon Schubert.\"    contributors may be used to endorse or promote products derived
18*25dffe65SSimon Schubert.\"    from this software without specific, prior written permission.
19*25dffe65SSimon Schubert.\"
20*25dffe65SSimon Schubert.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21*25dffe65SSimon Schubert.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22*25dffe65SSimon Schubert.\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23*25dffe65SSimon Schubert.\" FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
24*25dffe65SSimon Schubert.\" COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25*25dffe65SSimon Schubert.\" INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
26*25dffe65SSimon Schubert.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27*25dffe65SSimon Schubert.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28*25dffe65SSimon Schubert.\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29*25dffe65SSimon Schubert.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
30*25dffe65SSimon Schubert.\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31*25dffe65SSimon Schubert.\" SUCH DAMAGE.
32*25dffe65SSimon Schubert.\"
33*25dffe65SSimon Schubert.\" $DragonFly: src/lib/libc/sys/lwp_create.2,v 1.1 2007/03/12 21:06:18 corecode Exp $
34*25dffe65SSimon Schubert.\"
35*25dffe65SSimon Schubert.Dd March 12, 2007
36*25dffe65SSimon Schubert.Dt LWP_CREATE 2
37*25dffe65SSimon Schubert.Os
38*25dffe65SSimon Schubert.Sh NAME
39*25dffe65SSimon Schubert.Nm lwp_create
40*25dffe65SSimon Schubert.Nd spawn a new lwp
41*25dffe65SSimon Schubert.Sh LIBRARY
42*25dffe65SSimon Schubert.Lb libc
43*25dffe65SSimon Schubert.Sh SYNOPSIS
44*25dffe65SSimon Schubert.In unistd.h
45*25dffe65SSimon Schubert.Ft int
46*25dffe65SSimon Schubert.Fn lwp_create "struct lwp_params *params"
47*25dffe65SSimon Schubert.Sh DESCRIPTION
48*25dffe65SSimon SchubertThe
49*25dffe65SSimon Schubert.Fn lwp_create
50*25dffe65SSimon Schubertfunction is used to spawn a new lwp in the current process.
51*25dffe65SSimon SchubertIn some way, this is like
52*25dffe65SSimon Schubert.Xr fork 2 ,
53*25dffe65SSimon Schuberthowever
54*25dffe65SSimon Schubert.Fn lwp_create
55*25dffe65SSimon Schubertdoes not return twice as parent and child.
56*25dffe65SSimon SchubertInstead, the new lwp will start running a function which
57*25dffe65SSimon Schubertis provided with the parameters
58*25dffe65SSimon Schubert.Fa params ,
59*25dffe65SSimon Schubertas outlined below.
60*25dffe65SSimon Schubert.Bd -literal
61*25dffe65SSimon Schubertstruct lwp_params {
62*25dffe65SSimon Schubert	void (*func)(void *);	/* Function to start execution */
63*25dffe65SSimon Schubert	void *arg;		/* Parameter to this function */
64*25dffe65SSimon Schubert	void *stack;		/* Stack address to use */
65*25dffe65SSimon Schubert	lwpid_t *tid1;		/* Address to copy out new tid */
66*25dffe65SSimon Schubert	lwpid_t *tid2;		/* Same */
67*25dffe65SSimon Schubert};
68*25dffe65SSimon Schubert.Ed
69*25dffe65SSimon Schubert.Pp
70*25dffe65SSimon SchubertThe
71*25dffe65SSimon Schubert.Fa params
72*25dffe65SSimon Schubertpassed to
73*25dffe65SSimon Schubert.Fn lwp_create
74*25dffe65SSimon Schubertare as follows.
75*25dffe65SSimon SchubertSet
76*25dffe65SSimon Schubert.Fa func
77*25dffe65SSimon Schubertto specify the function to be executed in the new lwp.
78*25dffe65SSimon SchubertIt is the duty of
79*25dffe65SSimon Schubert.Fa func
80*25dffe65SSimon Schubertto terminate
81*25dffe65SSimon Schubertexecution of the lwp correctly, either by calling
82*25dffe65SSimon Schubert.Xr extexit 2
83*25dffe65SSimon Schubertor
84*25dffe65SSimon Schubert.Xr exit 3 .
85*25dffe65SSimon SchubertIf the
86*25dffe65SSimon Schubert.Fa func
87*25dffe65SSimon Schubertsimply returns, behavior is unspecified.
88*25dffe65SSimon SchubertThe only function argument passed to
89*25dffe65SSimon Schubert.Fa func
90*25dffe65SSimon Schubertis
91*25dffe65SSimon Schubert.Fa arg .
92*25dffe65SSimon Schubert.Pp
93*25dffe65SSimon SchubertThe new lwp starts out with its stack frame set to
94*25dffe65SSimon Schubert.Fa stack .
95*25dffe65SSimon SchubertThis parameter, like
96*25dffe65SSimon Schubert.Fa func
97*25dffe65SSimon Schubertis mandatory.  If any of these is invalid, behavior is
98*25dffe65SSimon Schubertunspecified.
99*25dffe65SSimon Schubert.Pp
100*25dffe65SSimon SchubertThe fields
101*25dffe65SSimon Schubert.Fa tid1
102*25dffe65SSimon Schubertand
103*25dffe65SSimon Schubert.Fa tid2
104*25dffe65SSimon Schubertpoint to variables where the tid of the new lwp should be stored.
105*25dffe65SSimon SchubertThere are two parameters so that storage for both parent
106*25dffe65SSimon Schubertand child can be specified separately.  Set any of these fields to
107*25dffe65SSimon SchubertNULL in case you don't need the tid to be copied out.
108*25dffe65SSimon Schubert.Sh RETURN VALUES
109*25dffe65SSimon SchubertUpon successful completion, the value 0 is returned;
110*25dffe65SSimon Schubertotherwise the value -1 is returned and
111*25dffe65SSimon Schubert.Va errno
112*25dffe65SSimon Schubertwill be set to
113*25dffe65SSimon Schubert.Er EINVAL .
114*25dffe65SSimon Schubert.Sh SEE ALSO
115*25dffe65SSimon Schubert.Xr extexit 2 ,
116*25dffe65SSimon Schubert.Xr rfork 2 ,
117*25dffe65SSimon Schubert.Xr exit 3
118*25dffe65SSimon Schubert.Sh HISTORY
119*25dffe65SSimon SchubertThe
120*25dffe65SSimon Schubert.Fn lwp_create
121*25dffe65SSimon Schubertfunction first appeared in
122*25dffe65SSimon Schubert.Dx 1.9 .
123