xref: /openbsd-src/lib/libpthread/man/pthread_exit.3 (revision e401f658b3625e16fc7d5f84f568d547ee36e359)
1*e401f658Sschwarze.\" $OpenBSD: pthread_exit.3,v 1.13 2017/01/27 15:47:47 schwarze Exp $
282d2d131Sfgsch.\"
3a278733dSd.\" Copyright (c) 1996 John Birrell <jb@cimlogic.com.au>.
4a278733dSd.\" All rights reserved.
5a278733dSd.\"
6a278733dSd.\" Redistribution and use in source and binary forms, with or without
7a278733dSd.\" modification, are permitted provided that the following conditions
8a278733dSd.\" are met:
9a278733dSd.\" 1. Redistributions of source code must retain the above copyright
10a278733dSd.\"    notice, this list of conditions and the following disclaimer.
11a278733dSd.\" 2. Redistributions in binary form must reproduce the above copyright
12a278733dSd.\"    notice, this list of conditions and the following disclaimer in the
13a278733dSd.\"    documentation and/or other materials provided with the distribution.
14a278733dSd.\" 3. All advertising materials mentioning features or use of this software
15a278733dSd.\"    must display the following acknowledgement:
16a278733dSd.\"	This product includes software developed by John Birrell.
17a278733dSd.\" 4. Neither the name of the author nor the names of any co-contributors
18a278733dSd.\"    may be used to endorse or promote products derived from this software
19a278733dSd.\"    without specific prior written permission.
20a278733dSd.\"
21a278733dSd.\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
22a278733dSd.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23a278733dSd.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24a278733dSd.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25a278733dSd.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26a278733dSd.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27a278733dSd.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28a278733dSd.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29a278733dSd.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30a278733dSd.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31a278733dSd.\" SUCH DAMAGE.
32a278733dSd.\"
3374493c91Sd.\" $FreeBSD: pthread_exit.3,v 1.7 1999/08/28 00:03:06 peter Exp $
3474493c91Sd.\"
35*e401f658Sschwarze.Dd $Mdocdate: January 27 2017 $
36a278733dSd.Dt PTHREAD_EXIT 3
37c043c0f7Sd.Os
38a278733dSd.Sh NAME
39a278733dSd.Nm pthread_exit
40a278733dSd.Nd terminate the calling thread
41a278733dSd.Sh SYNOPSIS
4286f9d4cdStedu.In pthread.h
43a278733dSd.Ft void
44a278733dSd.Fn pthread_exit "void *value_ptr"
45a278733dSd.Sh DESCRIPTION
46a278733dSdThe
47a278733dSd.Fn pthread_exit
48a278733dSdfunction terminates the calling thread and makes the value
49a278733dSd.Fa value_ptr
50ee997aeaSmpechavailable to any successful join with the terminating thread.
51ee997aeaSmpechAny
52a278733dSdcancellation cleanup handlers that have been pushed and are not yet popped
53a278733dSdare popped in the reverse order that they were pushed and then executed.
54a278733dSdAfter all cancellation handlers have been executed, if the thread has any
55a278733dSdthread-specific data, appropriate destructor functions are called in an
56ee997aeaSmpechunspecified order.
57ee997aeaSmpechThread termination does not release any application
58a278733dSdvisible process resources, including, but not limited to, mutexes and
59a278733dSdfile descriptors, nor does it perform any process level cleanup
60a278733dSdactions, including, but not limited to, calling
61a278733dSd.Fn atexit
62a278733dSdroutines that may exist.
63a278733dSd.Pp
64a278733dSdAn implicit call to
65a278733dSd.Fn pthread_exit
66a278733dSdis made when a thread other than the thread in which
67a278733dSd.Fn main
68*e401f658Sschwarzewas first invoked returns from the start routine that was used to
69*e401f658Sschwarzecreate it.
70*e401f658SschwarzeThe function's return value serves as the thread's exit status.
71a278733dSd.Pp
72a278733dSdThe behavior of
73a278733dSd.Fn pthread_exit
74ea5237b9Sderaadtis undefined if called from a cancellation handler or destructor function
75a278733dSdthat was invoked as the result of an implicit or explicit call to
76a278733dSd.Fn pthread_exit .
77a278733dSd.Pp
78a278733dSdAfter a thread has terminated, the result of access to local (auto)
79ee997aeaSmpechvariables of the thread is undefined.
80ee997aeaSmpechThus, references to local variables
81a278733dSdof the exiting thread should not be used for the
82a278733dSd.Fn pthread_exit
83a278733dSd.Fa value_ptr
84a278733dSdparameter value.
85a278733dSd.Pp
86a278733dSdThe process will exit with an exit status of 0 after the last thread has
87ee997aeaSmpechbeen terminated.
88ee997aeaSmpechThe behavior is as if the implementation called
89a278733dSd.Fn exit
90a278733dSdwith a zero argument at thread termination time.
91a278733dSd.Sh RETURN VALUES
92a278733dSdThe
93a278733dSd.Fn pthread_exit
94a278733dSdfunction cannot return to its caller.
95a278733dSd.Sh ERRORS
96a278733dSdNone.
97a278733dSd.Sh SEE ALSO
98a278733dSd.Xr _exit 2 ,
99b4059cf6Sd.Xr exit 3 ,
100a278733dSd.Xr pthread_create 3 ,
101a278733dSd.Xr pthread_join 3
102a278733dSd.Sh STANDARDS
103a278733dSd.Fn pthread_exit
10482d2d131Sfgschconforms to
10582d2d131Sfgsch.St -p1003.1-96 .
106