|
|
#include <sys/lwp.h>
int _lwp_create(ucontext_t *contextp, unsigned long flags, lwpid_t *new_lwp);
The function _lwp_create() adds a lightweight process (LWP) to the current process. The contextp parameter specifies the initial signal mask, stack, and machine context (including the program counter and stack pointer) for the new LWP. The new LWP inherits the scheduling class and priority of the caller.
If _lwp_create() is successful and new_lwp is not null, the ID of the new LWP is stored in the location pointed to by new_lwp.
flags specifies additional attributes for the new LWP. The value in flags is constructed by the bit-wise inclusive OR of the following values:
If LWP_DETACHED is specified, then the LWP is created in the detached state. Otherwise the LWP is created in the undetached state. The ID (and system resources) associated with a detached LWP can be automatically reclaimed when the LWP exits. The ID of an undetached LWP cannot be reclaimed until it exits and another LWP has reported its termination by way of _lwp_wait.2 This allows the waiting LWP to determine that the waited for LWP has terminated and to reclaim any process resources that it was using.
If LWP_SUSPENDED is specified, then the LWP is created in a suspended state. This allows the creator to change the LWP's inherited attributes before it starts to execute. The suspended LWP can only be resumed by way of _lwp_continue.2 If LWP_SUSPENDED is not specified the LWP can begin to run immediately after it has been created.
0 is returned when successful. A non-zero value indicates an error.
If any of the following conditions are detected, _lwp_create() fails and returns the corresponding value:
This example shows how a stack is allocated to a new LWP. _lwp_makecontext() is used to set up the context parameter so that the new LWP begins executing a function.
contextp = (ucontext_t *)malloc(sizeof(ucontext_t)); stackbase = malloc(stacksize); sigprocmask(SIGSETMASK, NULL, &contextp->uc_sigmask); _lwp_makecontext(contextp, func, arg, private, stackbase, stacksize); error = _lwp_create(contextp, NULL, &new_lwp);
Beginning with Solaris 2.5, the signal SIGALRM is defined to be per-process. This does not affect the behavior of single-threaded or multi-threaded applications. If the application was using LWPs directly, and was relying on alarm.2 or sleep.3c then the application's behavior might be impacted. The calling LWP will not necessarily be the recipient of the SIGARLM signal when SIGALRM is sent to the process. You might have to use a substitute like poll.2 or _lwp_cond_timedwait.2 to simulate the old per- LWP semantic of SIGALRM.
|
|
Created by unroff & hp-tools. © by Hans-Peter Bischof. All Rights Reserved (1997).
Last modified 07/October/97