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       noreturn 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  an‐
18       other 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  at‐
43       tributes(7).
44
45       ┌────────────────────────────────────────────┬───────────────┬─────────┐
46Interface                                   Attribute     Value   
47       ├────────────────────────────────────────────┼───────────────┼─────────┤
48pthread_exit()                              │ Thread safety │ MT-Safe │
49       └────────────────────────────────────────────┴───────────────┴─────────┘
50

CONFORMING TO

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

NOTES

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

BUGS

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

SEE ALSO

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

COLOPHON

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