OSDN Git Service

(split) LDP: Update original to LDP v3.38.
[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 .fi
35 .SH DESCRIPTION
36 The
37 .BR pthread_exit ()
38 function terminates the calling thread and returns a value via
39 .I retval
40 that (if the thread is joinable)
41 is available to another thread in the same process that calls
42 .BR pthread_join (3).
43
44 Any clean-up handlers established by
45 .BR pthread_cleanup_push (3)
46 that have not yet been popped,
47 are popped (in the reverse of the order in which they were pushed)
48 and executed.
49 If the thread has any thread-specific data, then,
50 after the clean-up handlers have been executed,
51 the corresponding destructor functions are called,
52 in an unspecified order.
53
54 When a thread terminates,
55 process-shared resources (e.g., mutexes, condition variables,
56 semaphores, and file descriptors) are not released,
57 and functions registered using
58 .BR atexit (3)
59 are not called.
60
61 After the last thread in a process terminates,
62 the process terminates as by calling
63 .BR exit (3)
64 with an exit status of zero;
65 thus, process-shared resources
66 are released and functions registered using
67 .BR atexit (3)
68 are called.
69 .SH RETURN VALUE
70 This function does not return to the caller.
71 .SH ERRORS
72 This function always succeeds.
73 .SH CONFORMING TO
74 POSIX.1-2001.
75 .SH NOTES
76 Performing a return from the start function of any thread other
77 than the main thread results in an implicit call to
78 .BR pthread_exit (),
79 using the function's return value as the thread's exit status.
80
81 To allow other threads to continue execution,
82 the main thread should terminate by calling
83 .BR pthread_exit ()
84 rather than
85 .BR exit (3).
86
87 The value pointed to by
88 .IR retval
89 should not be located on the calling thread's stack,
90 since the contents of that stack are undefined after the thread terminates.
91 .SH BUGS
92 Currently,
93 .\" Linux 2.6.27
94 there are limitations in the kernel implementation logic for
95 .BR wait (2)ing
96 on a stopped thread group with a dead thread group leader.
97 This can manifest in problems such as a locked terminal if a stop signal is
98 sent to a foreground process whose thread group leader has already called
99 .BR pthread_exit ().
100 .\" FIXME . review a later kernel to see if this gets fixed
101 .\" http://thread.gmane.org/gmane.linux.kernel/611611
102 .\" http://marc.info/?l=linux-kernel&m=122525468300823&w=2
103 .SH SEE ALSO
104 .BR pthread_create (3),
105 .BR pthread_join (3),
106 .BR pthreads (7)