1PTHREAD_EXIT(3P)           POSIX Programmer's Manual          PTHREAD_EXIT(3P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10
11

NAME

13       pthread_exit — thread termination
14

SYNOPSIS

16       #include <pthread.h>
17
18       void pthread_exit(void *value_ptr);
19

DESCRIPTION

21       The pthread_exit() function shall terminate the calling thread and make
22       the value value_ptr available to any successful join with the terminat‐
23       ing thread. Any cancellation cleanup handlers that have been pushed and
24       not  yet  popped  shall  be  popped in the reverse order that they were
25       pushed and then executed. After all cancellation cleanup handlers  have
26       been  executed, if the thread has any thread-specific data, appropriate
27       destructor functions shall be called in an  unspecified  order.  Thread
28       termination does not release any application visible process resources,
29       including, but not limited to, mutexes and file descriptors,  nor  does
30       it  perform  any process-level cleanup actions, including, but not lim‐
31       ited to, calling any atexit() routines that may exist.
32
33       An implicit call to pthread_exit() is made when a thread other than the
34       thread in which main() was first invoked returns from the start routine
35       that was used to create it. The function's return value shall serve  as
36       the thread's exit status.
37
38       The  behavior of pthread_exit() is undefined if called from a cancella‐
39       tion cleanup handler or destructor  function  that  was  invoked  as  a
40       result of either an implicit or explicit call to pthread_exit().
41
42       After  a  thread  has  terminated, the result of access to local (auto)
43       variables of the thread is undefined. Thus, references to  local  vari‐
44       ables  of  the exiting thread should not be used for the pthread_exit()
45       value_ptr parameter value.
46
47       The process shall exit with an exit status of 0 after the  last  thread
48       has  been  terminated.  The  behavior shall be as if the implementation
49       called exit() with a zero argument at thread termination time.
50

RETURN VALUE

52       The pthread_exit() function cannot return to its caller.
53

ERRORS

55       No errors are defined.
56
57       The following sections are informative.
58

EXAMPLES

60       None.
61

APPLICATION USAGE

63       None.
64

RATIONALE

66       The normal mechanism by which a thread terminates is to return from the
67       routine  that  was  specified in the pthread_create() call that started
68       it. The pthread_exit() function provides the capability for a thread to
69       terminate  without  requiring  a  return from the start routine of that
70       thread, thereby providing a function analogous to exit().
71
72       Regardless of  the  method  of  thread  termination,  any  cancellation
73       cleanup handlers that have been pushed and not yet popped are executed,
74       and the destructors for any existing thread-specific data are executed.
75       This volume of POSIX.1‐2008 requires that cancellation cleanup handlers
76       be popped and called in order. After all cancellation cleanup  handlers
77       have  been executed, thread-specific data destructors are called, in an
78       unspecified order, for each item of thread-specific data that exists in
79       the  thread.  This  ordering  is necessary because cancellation cleanup
80       handlers may rely on thread-specific data.
81
82       As the meaning of the status is determined by the  application  (except
83       when  the  thread  has  been canceled, in which case it is PTHREAD_CAN‐
84       CELED), the implementation has no idea what an illegal status value is,
85       which is why no address error checking is done.
86

FUTURE DIRECTIONS

88       None.
89

SEE ALSO

91       exit(), pthread_create(), pthread_join()
92
93       The Base Definitions volume of POSIX.1‐2008, <pthread.h>
94
96       Portions  of  this text are reprinted and reproduced in electronic form
97       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
98       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
99       Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
100       cal  and  Electronics  Engineers,  Inc  and  The  Open Group.  (This is
101       POSIX.1-2008 with the 2013 Technical Corrigendum  1  applied.)  In  the
102       event of any discrepancy between this version and the original IEEE and
103       The Open Group Standard, the original IEEE and The Open Group  Standard
104       is  the  referee document. The original Standard can be obtained online
105       at http://www.unix.org/online.html .
106
107       Any typographical or formatting errors that appear  in  this  page  are
108       most likely to have been introduced during the conversion of the source
109       files to man page format. To report such errors,  see  https://www.ker
110       nel.org/doc/man-pages/reporting_bugs.html .
111
112
113
114IEEE/The Open Group                  2013                     PTHREAD_EXIT(3P)
Impressum