LWP_CREATE(2) BSD System Calls Manual LWP_CREATE(2)NAMElwp_create — spawn a new lwp
LIBRARY
Standard C Library (libc, -lc)
SYNOPSIS
#include <unistd.h>
int
lwp_create(struct lwp_params *params);
DESCRIPTION
The lwp_create() function spawns a new lwp in the current process. In a
way, lwp_create() is similar to fork(2). However, lwp_create() does 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, behav‐
ior 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 unspeci‐
fied.
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.
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 ALSOextexit(2), rfork(2), exit(3)HISTORY
The lwp_create() function first appeared in DragonFly 1.9.
BSD March 12, 2007 BSD