1PTHREAD_EXIT(3)            Linux Programmer's Manual           PTHREAD_EXIT(3)
2
3
4

NAME

6       pthread_exit - terminate calling thread
7

SYNOPSIS

9       #include <pthread.h>
10
11       void pthread_exit(void *retval);
12
13       Compile and link with -pthread.
14

DESCRIPTION

16       The pthread_exit() function terminates the calling thread and returns a
17       value via retval that (if the  thread  is  joinable)  is  available  to
18       another thread in the same process that calls pthread_join(3).
19
20       Any  clean-up handlers established by pthread_cleanup_push(3) that have
21       not yet been popped, are popped (in the reverse of the order  in  which
22       they  were pushed) and executed.  If the thread has any thread-specific
23       data, then, after the clean-up handlers have been executed, the  corre‐
24       sponding destructor functions are called, in an unspecified order.
25
26       When a thread terminates, process-shared resources (e.g., mutexes, con‐
27       dition variables, semaphores, and file descriptors) are  not  released,
28       and functions registered using atexit(3) are not called.
29
30       After  the  last thread in a process terminates, the process terminates
31       as by calling exit(3) with an exit status of zero; thus, process-shared
32       resources  are  released  and  functions registered using atexit(3) are
33       called.
34

RETURN VALUE

36       This function does not return to the caller.
37

ERRORS

39       This function always succeeds.
40

ATTRIBUTES

42       For  an  explanation  of  the  terms  used   in   this   section,   see
43       attributes(7).
44
45       ┌───────────────┬───────────────┬─────────┐
46Interface      Attribute     Value   
47       ├───────────────┼───────────────┼─────────┤
48pthread_exit() │ Thread safety │ MT-Safe │
49       └───────────────┴───────────────┴─────────┘

CONFORMING TO

51       POSIX.1-2001, POSIX.1-2008.
52

NOTES

54       Performing  a  return  from the start function of any thread other than
55       the main thread results in an implicit call  to  pthread_exit(),  using
56       the function's return value as the thread's exit status.
57
58       To  allow  other  threads to continue execution, the main thread should
59       terminate by calling pthread_exit() rather than exit(3).
60
61       The value pointed to by retval should not be  located  on  the  calling
62       thread's  stack,  since  the contents of that stack are undefined after
63       the thread terminates.
64

BUGS

66       Currently, there are limitations in the kernel implementation logic for
67       wait(2)ing  on  a stopped thread group with a dead thread group leader.
68       This can manifest in problems such as a locked terminal if a stop  sig‐
69       nal  is  sent  to  a  foreground  process whose thread group leader has
70       already called pthread_exit().
71

SEE ALSO

73       pthread_create(3), pthread_join(3), pthreads(7)
74

COLOPHON

76       This page is part of release 5.04 of the Linux  man-pages  project.   A
77       description  of  the project, information about reporting bugs, and the
78       latest    version    of    this    page,    can     be     found     at
79       https://www.kernel.org/doc/man-pages/.
80
81
82
83Linux                             2017-09-15                   PTHREAD_EXIT(3)
Impressum