xref: /dflybsd-src/lib/libc/sys/lwp_create.2 (revision 25e1dde1095663c097efd06d5e99449f430ba5ac)
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.\"
331eb8c611SSepherosa Ziehau.Dd January 14, 2017
3425dffe65SSimon Schubert.Dt LWP_CREATE 2
3525dffe65SSimon Schubert.Os
3625dffe65SSimon Schubert.Sh NAME
371eb8c611SSepherosa Ziehau.Nm lwp_create ,
381eb8c611SSepherosa Ziehau.Nm lwp_create2
3925dffe65SSimon Schubert.Nd spawn a new lwp
4025dffe65SSimon Schubert.Sh LIBRARY
4125dffe65SSimon Schubert.Lb libc
4225dffe65SSimon Schubert.Sh SYNOPSIS
43*0d9899e7SSepherosa Ziehau.In sys/lwp.h
4425dffe65SSimon Schubert.Ft int
4525dffe65SSimon Schubert.Fn lwp_create "struct lwp_params *params"
461eb8c611SSepherosa Ziehau.Ft int
471eb8c611SSepherosa Ziehau.Fn lwp_create2 "struct lwp_params *params" "const cpumask_t *mask"
4825dffe65SSimon Schubert.Sh DESCRIPTION
4925dffe65SSimon SchubertThe
5025dffe65SSimon Schubert.Fn lwp_create
511eb8c611SSepherosa Ziehauand the
521eb8c611SSepherosa Ziehau.Fn lwp_create2
531eb8c611SSepherosa Ziehaufunction spawn a new lwp in the current process.
540ca980deSSascha WildnerIn a way,
550ca980deSSascha Wildner.Fn lwp_create
561eb8c611SSepherosa Ziehauand
571eb8c611SSepherosa Ziehau.Fn lwp_create2
581eb8c611SSepherosa Ziehauare similar to
590ca980deSSascha Wildner.Xr fork 2 .
600ca980deSSascha WildnerHowever,
6125dffe65SSimon Schubert.Fn lwp_create
621eb8c611SSepherosa Ziehauand
631eb8c611SSepherosa Ziehau.Fn lwp_create2
641eb8c611SSepherosa Ziehaudo not return twice as parent and child.
650ca980deSSascha WildnerInstead, the new lwp will execute a function provided by the
660ca980deSSascha Wildner.Fa params
670ca980deSSascha Wildnerargument which is a pointer to a
680ca980deSSascha Wildner.Vt struct lwp_params .
6925dffe65SSimon Schubert.Bd -literal
7025dffe65SSimon Schubertstruct lwp_params {
7125dffe65SSimon Schubert	void (*func)(void *);	/* Function to start execution */
7225dffe65SSimon Schubert	void *arg;		/* Parameter to this function */
7325dffe65SSimon Schubert	void *stack;		/* Stack address to use */
7425dffe65SSimon Schubert	lwpid_t *tid1;		/* Address to copy out new tid */
7525dffe65SSimon Schubert	lwpid_t *tid2;		/* Same */
7625dffe65SSimon Schubert};
7725dffe65SSimon Schubert.Ed
7825dffe65SSimon Schubert.Pp
790ca980deSSascha WildnerA function pointer
8025dffe65SSimon Schubert.Fa func
810ca980deSSascha Wildnerspecifies the function to be executed in the new lwp.
8225dffe65SSimon SchubertIt is the duty of
830ca980deSSascha Wildner.Fn func
840ca980deSSascha Wildnerto correctly terminate execution of the lwp, either by calling
8525dffe65SSimon Schubert.Xr extexit 2
8625dffe65SSimon Schubertor
8725dffe65SSimon Schubert.Xr exit 3 .
880ca980deSSascha WildnerIf
890ca980deSSascha Wildner.Fn func
900ca980deSSascha Wildnerreturns, behavior is unspecified.
910ca980deSSascha WildnerThe only argument passed to
920ca980deSSascha Wildner.Fn func
9325dffe65SSimon Schubertis
9425dffe65SSimon Schubert.Fa arg .
9525dffe65SSimon Schubert.Pp
960ca980deSSascha WildnerThe new lwp starts with its stack frame set to
9725dffe65SSimon Schubert.Fa stack .
980ca980deSSascha WildnerNote that both
9925dffe65SSimon Schubert.Fa func
1000ca980deSSascha Wildnerand
1010ca980deSSascha Wildner.Fa stack
1020ca980deSSascha Wildnerare mandatory.
1030ca980deSSascha WildnerIf either is invalid, behavior is
10425dffe65SSimon Schubertunspecified.
10525dffe65SSimon Schubert.Pp
10625dffe65SSimon SchubertThe fields
10725dffe65SSimon Schubert.Fa tid1
10825dffe65SSimon Schubertand
10925dffe65SSimon Schubert.Fa tid2
1100ca980deSSascha Wildnerpoint to variables where the tid of the new lwp shall be stored.
1110ca980deSSascha WildnerTwo parameters are provided so that storage for both parent
1120ca980deSSascha Wildnerand child can be specified separately.
1130ca980deSSascha WildnerSetting any of these to NULL causes the respective tid not to be copied out.
1141eb8c611SSepherosa Ziehau.Pp
1151eb8c611SSepherosa ZiehauThe
1161eb8c611SSepherosa Ziehau.Fa mask
1171eb8c611SSepherosa Ziehauargument to
1181eb8c611SSepherosa Ziehau.Fn lwp_create2
1191eb8c611SSepherosa Ziehauspecifies the new lwp's CPU affinity mask.
1201eb8c611SSepherosa Ziehau.Va NULL
1211eb8c611SSepherosa Ziehaumeans no special CPU affinity settings.
12225dffe65SSimon Schubert.Sh RETURN VALUES
1230ca980deSSascha Wildner.Rv -std
12425dffe65SSimon Schubert.Sh SEE ALSO
12525dffe65SSimon Schubert.Xr extexit 2 ,
12625dffe65SSimon Schubert.Xr rfork 2 ,
12725dffe65SSimon Schubert.Xr exit 3
12825dffe65SSimon Schubert.Sh HISTORY
12925dffe65SSimon SchubertThe
13025dffe65SSimon Schubert.Fn lwp_create
13125dffe65SSimon Schubertfunction first appeared in
13225dffe65SSimon Schubert.Dx 1.9 .
1331eb8c611SSepherosa ZiehauThe
1341eb8c611SSepherosa Ziehau.Fn lwp_create2
1351eb8c611SSepherosa Ziehaufunction first appeared in
1361eb8c611SSepherosa Ziehau.Dx 4.7 .
137