DragonFly On-Line Manual Pages
LWP_CREATE(2) DragonFly System Calls Manual LWP_CREATE(2)
NAME
lwp_create, lwp_create2 -- spawn a new lwp
LIBRARY
Standard C Library (libc, -lc)
SYNOPSIS
#include <sys/lwp.h>
int
lwp_create(struct lwp_params *params);
int
lwp_create2(struct lwp_params *params, const cpumask_t *mask);
DESCRIPTION
The lwp_create() and the lwp_create2() function spawn a new lwp in the
current process. In a way, lwp_create() and lwp_create2() are similar to
fork(2). However, lwp_create() and lwp_create2() do not return twice as
parent and child. Instead, the new lwp will execute a function provided
by the params argument which is a pointer to a struct lwp_params.
struct lwp_params {
void (*func)(void *); /* Function to start execution */
void *arg; /* Parameter to this function */
void *stack; /* Stack address to use */
lwpid_t *tid1; /* Address to copy out new tid */
lwpid_t *tid2; /* Same */
};
A function pointer func specifies the function to be executed in the new
lwp. It is the duty of func() to correctly terminate execution of the
lwp, either by calling extexit(2) or exit(3). If func() returns,
behavior is unspecified. The only argument passed to func() is arg.
The new lwp starts with its stack frame set to stack. Note that both
func and stack are mandatory. If either is invalid, behavior is
unspecified.
The fields tid1 and tid2 point to variables where the tid of the new lwp
shall be stored. Two parameters are provided so that storage for both
parent and child can be specified separately. Setting any of these to
NULL causes the respective tid not to be copied out.
The mask argument to lwp_create2() specifies the new lwp's CPU affinity
mask. NULL means no special CPU affinity settings.
RETURN VALUES
Upon successful completion, the value 0 is returned; otherwise the
value -1 is returned and the global variable errno is set to indicate the
error.
SEE ALSO
extexit(2), rfork(2), exit(3)
HISTORY
The lwp_create() function first appeared in DragonFly 1.9. The
lwp_create2() function first appeared in DragonFly 4.7.
DragonFly 4.7 January 14, 2017 DragonFly 4.7