xref: /dflybsd-src/lib/libc/sys/lwp_create.2 (revision 1eb8c61101afd79c1b21b3eeac68b4d1528df580)
125dffe65SSimon Schubert.\" Copyright (c) 2007 The DragonFly Project.  All rights reserved.
225dffe65SSimon Schubert.\"
325dffe65SSimon Schubert.\" This code is derived from software contributed to The DragonFly Project
425dffe65SSimon Schubert.\" by Simon 'corecode' Schubert <corecode@fs.ei.tum.de>
525dffe65SSimon Schubert.\"
625dffe65SSimon Schubert.\" Redistribution and use in source and binary forms, with or without
725dffe65SSimon Schubert.\" modification, are permitted provided that the following conditions
825dffe65SSimon Schubert.\" are met:
925dffe65SSimon Schubert.\"
1025dffe65SSimon Schubert.\" 1. Redistributions of source code must retain the above copyright
1125dffe65SSimon Schubert.\"    notice, this list of conditions and the following disclaimer.
1225dffe65SSimon Schubert.\" 2. Redistributions in binary form must reproduce the above copyright
1325dffe65SSimon Schubert.\"    notice, this list of conditions and the following disclaimer in
1425dffe65SSimon Schubert.\"    the documentation and/or other materials provided with the
1525dffe65SSimon Schubert.\"    distribution.
1625dffe65SSimon Schubert.\" 3. Neither the name of The DragonFly Project nor the names of its
1725dffe65SSimon Schubert.\"    contributors may be used to endorse or promote products derived
1825dffe65SSimon Schubert.\"    from this software without specific, prior written permission.
1925dffe65SSimon Schubert.\"
2025dffe65SSimon Schubert.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2125dffe65SSimon Schubert.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2225dffe65SSimon Schubert.\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
2325dffe65SSimon Schubert.\" FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
2425dffe65SSimon Schubert.\" COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
2525dffe65SSimon Schubert.\" INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
2625dffe65SSimon Schubert.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
2725dffe65SSimon Schubert.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
2825dffe65SSimon Schubert.\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
2925dffe65SSimon Schubert.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
3025dffe65SSimon Schubert.\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3125dffe65SSimon Schubert.\" SUCH DAMAGE.
3225dffe65SSimon Schubert.\"
330ca980deSSascha Wildner.\" $DragonFly: src/lib/libc/sys/lwp_create.2,v 1.2 2007/03/13 10:16:56 swildner Exp $
3425dffe65SSimon Schubert.\"
35*1eb8c611SSepherosa Ziehau.Dd January 14, 2017
3625dffe65SSimon Schubert.Dt LWP_CREATE 2
3725dffe65SSimon Schubert.Os
3825dffe65SSimon Schubert.Sh NAME
39*1eb8c611SSepherosa Ziehau.Nm lwp_create,
40*1eb8c611SSepherosa Ziehau.Nm lwp_create2
4125dffe65SSimon Schubert.Nd spawn a new lwp
4225dffe65SSimon Schubert.Sh LIBRARY
4325dffe65SSimon Schubert.Lb libc
4425dffe65SSimon Schubert.Sh SYNOPSIS
4525dffe65SSimon Schubert.In unistd.h
4625dffe65SSimon Schubert.Ft int
4725dffe65SSimon Schubert.Fn lwp_create "struct lwp_params *params"
48*1eb8c611SSepherosa Ziehau.Ft int
49*1eb8c611SSepherosa Ziehau.Fn lwp_create2 "struct lwp_params *params" "const cpumask_t *mask"
5025dffe65SSimon Schubert.Sh DESCRIPTION
5125dffe65SSimon SchubertThe
5225dffe65SSimon Schubert.Fn lwp_create
53*1eb8c611SSepherosa Ziehauand the
54*1eb8c611SSepherosa Ziehau.Fn lwp_create2
55*1eb8c611SSepherosa Ziehaufunction spawn a new lwp in the current process.
560ca980deSSascha WildnerIn a way,
570ca980deSSascha Wildner.Fn lwp_create
58*1eb8c611SSepherosa Ziehauand
59*1eb8c611SSepherosa Ziehau.Fn lwp_create2
60*1eb8c611SSepherosa Ziehauare similar to
610ca980deSSascha Wildner.Xr fork 2 .
620ca980deSSascha WildnerHowever,
6325dffe65SSimon Schubert.Fn lwp_create
64*1eb8c611SSepherosa Ziehauand
65*1eb8c611SSepherosa Ziehau.Fn lwp_create2
66*1eb8c611SSepherosa Ziehaudo not return twice as parent and child.
670ca980deSSascha WildnerInstead, the new lwp will execute a function provided by the
680ca980deSSascha Wildner.Fa params
690ca980deSSascha Wildnerargument which is a pointer to a
700ca980deSSascha Wildner.Vt struct lwp_params .
7125dffe65SSimon Schubert.Bd -literal
7225dffe65SSimon Schubertstruct lwp_params {
7325dffe65SSimon Schubert	void (*func)(void *);	/* Function to start execution */
7425dffe65SSimon Schubert	void *arg;		/* Parameter to this function */
7525dffe65SSimon Schubert	void *stack;		/* Stack address to use */
7625dffe65SSimon Schubert	lwpid_t *tid1;		/* Address to copy out new tid */
7725dffe65SSimon Schubert	lwpid_t *tid2;		/* Same */
7825dffe65SSimon Schubert};
7925dffe65SSimon Schubert.Ed
8025dffe65SSimon Schubert.Pp
810ca980deSSascha WildnerA function pointer
8225dffe65SSimon Schubert.Fa func
830ca980deSSascha Wildnerspecifies the function to be executed in the new lwp.
8425dffe65SSimon SchubertIt is the duty of
850ca980deSSascha Wildner.Fn func
860ca980deSSascha Wildnerto correctly terminate execution of the lwp, either by calling
8725dffe65SSimon Schubert.Xr extexit 2
8825dffe65SSimon Schubertor
8925dffe65SSimon Schubert.Xr exit 3 .
900ca980deSSascha WildnerIf
910ca980deSSascha Wildner.Fn func
920ca980deSSascha Wildnerreturns, behavior is unspecified.
930ca980deSSascha WildnerThe only argument passed to
940ca980deSSascha Wildner.Fn func
9525dffe65SSimon Schubertis
9625dffe65SSimon Schubert.Fa arg .
9725dffe65SSimon Schubert.Pp
980ca980deSSascha WildnerThe new lwp starts with its stack frame set to
9925dffe65SSimon Schubert.Fa stack .
1000ca980deSSascha WildnerNote that both
10125dffe65SSimon Schubert.Fa func
1020ca980deSSascha Wildnerand
1030ca980deSSascha Wildner.Fa stack
1040ca980deSSascha Wildnerare mandatory.
1050ca980deSSascha WildnerIf either is invalid, behavior is
10625dffe65SSimon Schubertunspecified.
10725dffe65SSimon Schubert.Pp
10825dffe65SSimon SchubertThe fields
10925dffe65SSimon Schubert.Fa tid1
11025dffe65SSimon Schubertand
11125dffe65SSimon Schubert.Fa tid2
1120ca980deSSascha Wildnerpoint to variables where the tid of the new lwp shall be stored.
1130ca980deSSascha WildnerTwo parameters are provided so that storage for both parent
1140ca980deSSascha Wildnerand child can be specified separately.
1150ca980deSSascha WildnerSetting any of these to NULL causes the respective tid not to be copied out.
116*1eb8c611SSepherosa Ziehau.Pp
117*1eb8c611SSepherosa ZiehauThe
118*1eb8c611SSepherosa Ziehau.Fa mask
119*1eb8c611SSepherosa Ziehauargument to
120*1eb8c611SSepherosa Ziehau.Fn lwp_create2
121*1eb8c611SSepherosa Ziehauspecifies the new lwp's CPU affinity mask.
122*1eb8c611SSepherosa Ziehau.Va NULL
123*1eb8c611SSepherosa Ziehaumeans no special CPU affinity settings.
12425dffe65SSimon Schubert.Sh RETURN VALUES
1250ca980deSSascha Wildner.Rv -std
12625dffe65SSimon Schubert.Sh SEE ALSO
12725dffe65SSimon Schubert.Xr extexit 2 ,
12825dffe65SSimon Schubert.Xr rfork 2 ,
12925dffe65SSimon Schubert.Xr exit 3
13025dffe65SSimon Schubert.Sh HISTORY
13125dffe65SSimon SchubertThe
13225dffe65SSimon Schubert.Fn lwp_create
13325dffe65SSimon Schubertfunction first appeared in
13425dffe65SSimon Schubert.Dx 1.9 .
135*1eb8c611SSepherosa ZiehauThe
136*1eb8c611SSepherosa Ziehau.Fn lwp_create2
137*1eb8c611SSepherosa Ziehaufunction first appeared in
138*1eb8c611SSepherosa Ziehau.Dx 4.7 .
139