1pthread_exit(3)            Library Functions Manual            pthread_exit(3)
2
3
4

NAME

6       pthread_exit - terminate calling thread
7

LIBRARY

9       POSIX threads library (libpthread, -lpthread)
10

SYNOPSIS

12       #include <pthread.h>
13
14       [[noreturn]] void pthread_exit(void *retval);
15

DESCRIPTION

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

RETURN VALUE

37       This function does not return to the caller.
38

ERRORS

40       This function always succeeds.
41

ATTRIBUTES

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

STANDARDS

53       POSIX.1-2008.
54

HISTORY

56       POSIX.1-2001.
57

NOTES

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

BUGS

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

SEE ALSO

78       pthread_create(3), pthread_join(3), pthreads(7)
79
80
81
82Linux man-pages 6.04              2023-03-30                   pthread_exit(3)
Impressum