#include <sys/lwp.h>int _lwp_wait(lwpid_t wait_for, lwpid_t *departed_lwp);
The _lwp_wait() function blocks the current LWP until the LWP specified by wait_for terminates. If the specified LWP terminated prior to the call to _lwp_wait(), _lwp_wait() returns immediately. If wait_for is zero, _lwp_wait() waits for any undetached LWP in the current process. If wait_for is not zero, it must specify an undetached LWP in the current process. If departed_lwp is not NULL, it points to a location where the ID of the exited LWP is stored (see _lwp_exit(2)).
When an LWP exits and there are one or more LWPs in the process waiting for this specific LWP to exit, one of the waiting LWPs is unblocked and it returns from _lwp_wait() successfully. Any other LWPs waiting for this same LWP to exit are also unblocked, but they return from _lwp_wait() with an error (ESRCH) indicating the waited-for LWP no longer exists. If there are no LWPs in the process waiting for this specific LWP to exit but there are one or more LWPs waiting for any LWP to exit, one of the waiting LWPs is unblocked and it returns from _lwp_wait() successfully.
If an LWP is waiting for any LWP to exit, it blocks until an undetached LWP for which no other LWP is waiting terminates, at which time it returns successfully, or until all other LWPs in the process are either daemon LWPs or LWPs waiting in _lwp_wait(), in which case it returns EDEADLK.
The ID of an LWP that has exited may be reused via _lwp_create() after the LWP has been successfully waited for.
Upon successful completion, 0 is returned. A non-zero value indicates an error.
If any of the following conditions occur, _lwp_wait() fails and returns the corresponding value:
A wait deadlock was detected, such as when an LWP attempts to wait for itself, or the calling LWP is waiting for any LWP to exit and only daemon LWPs or waiting LWPs exist in the process.
The _lwp_wait() function was interrupted by a signal.
The LWP with the ID specified by wait_for is a detached LWP.
No LWP with the ID specified by wait_for can be found in the current process.
See attributes(5) for descriptions of the following attributes:
|ATTRIBUTE TYPE||ATTRIBUTE VALUE|