OSDN Git Service

4b8cb7b0c324566dd1379ca00a951b853f085039
[linuxjm/LDP_man-pages.git] / original / man3 / pthread_exit.3
1 .\" Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk
2 .\"     <mtk.manpages@gmail.com>
3 .\"
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein.  The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\"
24 .TH PTHREAD_EXIT 3 2009-03-30 "Linux" "Linux Programmer's Manual"
25 .SH NAME
26 pthread_exit \- terminate calling thread
27 .SH SYNOPSIS
28 .nf
29 .B #include <pthread.h>
30
31 .BI "void pthread_exit(void *" retval );
32 .sp
33 Compile and link with \fI\-pthread\fP.
34 .SH DESCRIPTION
35 The
36 .BR pthread_exit ()
37 function terminates the calling thread and returns a value via
38 .I retval
39 that (if the thread is joinable)
40 is available to another thread in the same process that calls
41 .BR pthread_join (3).
42
43 Any clean-up handlers established by
44 .BR pthread_cleanup_push (3)
45 that have not yet been popped,
46 are popped (in the reverse of the order in which they were pushed)
47 and executed.
48 If the thread has any thread-specific data, then,
49 after the clean-up handlers have been executed,
50 the corresponding destructor functions are called,
51 in an unspecified order.
52
53 When a thread terminates,
54 process-shared resources (e.g., mutexes, condition variables,
55 semaphores, and file descriptors) are not released,
56 and functions registered using
57 .BR atexit (3)
58 are not called.
59
60 After the last thread in a process terminates,
61 the process terminates as by calling
62 .BR exit (3)
63 with an exit status of zero;
64 thus, process-shared resources
65 are released and functions registered using
66 .BR atexit (3)
67 are called.
68 .SH RETURN VALUE
69 This function does not return to the caller.
70 .SH ERRORS
71 This function always succeeds.
72 .SH CONFORMING TO
73 POSIX.1-2001.
74 .SH NOTES
75 Performing a return from the start function of any thread other
76 than the main thread results in an implicit call to
77 .BR pthread_exit (),
78 using the function's return value as the thread's exit status.
79
80 To allow other threads to continue execution,
81 the main thread should terminate by calling
82 .BR pthread_exit ()
83 rather than
84 .BR exit (3).
85
86 The value pointed to by
87 .IR retval
88 should not be located on the calling thread's stack,
89 since the contents of that stack are undefined after the thread terminates.
90 .SH BUGS
91 Currently,
92 .\" Linux 2.6.27
93 there are limitations in the kernel implementation logic for
94 .BR wait (2)ing
95 on a stopped thread group with a dead thread group leader.
96 This can manifest in problems such as a locked terminal if a stop signal is
97 sent to a foreground process whose thread group leader has already called
98 .BR pthread_exit ().
99 .\" FIXME . review a later kernel to see if this gets fixed
100 .\" http://thread.gmane.org/gmane.linux.kernel/611611
101 .\" http://marc.info/?l=linux-kernel&m=122525468300823&w=2
102 .SH SEE ALSO
103 .BR pthread_create (3),
104 .BR pthread_join (3),
105 .BR pthreads (7)