pthread_exit(3T) SDK R4.11 pthread_exit(3T)
NAME
pthread_exit - terminate the calling thread
SYNOPSIS
#include <pthread.h>
void pthread_exit(void *status);
where:
status Exit status
DESCRIPTION
The pthread_exit() function terminates the calling thread and makes
the value given by status available to any successful join with the
terminating thread.
Any cleanup handlers which have been pushed and not yet popped are
popped in the reverse order that they were pushed and then executed.
After all cleanup handlers have been executed, if the thread has any
thread-specific data, appropriate destructor functions are called in
an unspecified order. Thread termination does not release any
application visible process resources, including, but not limited to,
mutexes and file descriptors.
If the calling thread is detached, then it cleans up after itself and
makes its resources and ID available for reuse by a subsequent
pthread_create(). Otherwise, if the thread has a joiner, the joiner
is awakened successfully and passed the value given by status. If
the thread has multiple joiners, one will wake up successfully, and
the others will wake up with an ESRCH error.
An implicit call to pthread_exit() is made when a thread, other than
the initial thread, returns from the start routine that was used to
create it, with the function's return value serving as the thread's
exit status. When the initial thread returns from main() an implicit
call to exit() is made with the return value serving as the process's
exit status.
The behavior of pthread_exit() is undefined if called from a cleanup
handler or destructor function that was invoked as a result of either
an implicit or explicit call to pthread_exit().
The process exits when the last unterminated thread calls
pthread_exit(). In this case, the exit status of the process is 0 if
this thread was detached and 1 otherwise.
DIAGNOSTICS
Returns
The pthread_exit() function never returns.
SEE ALSO
_exit(2), pthread_create(3T), pthread_join(3T).
NOTES
If the terminating thread is detached, it cannot possibly have any
joiners. It is illegal to join a detached thread.
Applications need to be particularly careful not to use the ID of a
terminated thread whose resources have been cleaned up via detachment
or joining (which performs an implicit detach). Such IDs can get
reused very quickly. Failure to heed thread ID lifetimes can lead to
unpredictable results. In particular, the wrong thread could be
manipulated.
When the last thread in a process terminates, the process is
terminated, but the process's file buffers are not automatically
flushed as they would have been with an explicit or implicit call to
exit().
Licensed material--property of copyright holder(s)