xref: /netbsd-src/lib/libpthread/pthread_cleanup_push.3 (revision d48f14661dda8638fee055ba15d35bdfb29b9fa8)
1.\" $NetBSD: pthread_cleanup_push.3,v 1.4 2003/07/04 08:42:20 wiz Exp $
2.\"
3.\" Copyright (c) 2002 The NetBSD Foundation, Inc.
4.\" All rights reserved.
5.\" Redistribution and use in source and binary forms, with or without
6.\" modification, are permitted provided that the following conditions
7.\" are met:
8.\" 1. Redistributions of source code must retain the above copyright
9.\"    notice, this list of conditions and the following disclaimer.
10.\" 2. Redistributions in binary form must reproduce the above copyright
11.\"    notice, this list of conditions and the following disclaimer in the
12.\"    documentation and/or other materials provided with the distribution.
13.\" 3. Neither the name of The NetBSD Foundation nor the names of its
14.\"    contributors may be used to endorse or promote products derived
15.\"    from this software without specific prior written permission.
16.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26.\" POSSIBILITY OF SUCH DAMAGE.
27.\"
28.\" Copyright (c) 1997 Brian Cully <shmit@kublai.com>
29.\" All rights reserved.
30.\"
31.\" Redistribution and use in source and binary forms, with or without
32.\" modification, are permitted provided that the following conditions
33.\" are met:
34.\" 1. Redistributions of source code must retain the above copyright
35.\"    notice, this list of conditions and the following disclaimer.
36.\" 2. Redistributions in binary form must reproduce the above copyright
37.\"    notice, this list of conditions and the following disclaimer in the
38.\"    documentation and/or other materials provided with the distribution.
39.\" 3. Neither the name of the author nor the names of any co-contributors
40.\"    may be used to endorse or promote products derived from this software
41.\"    without specific prior written permission.
42.\"
43.\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
44.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
47.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
48.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
49.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
51.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
52.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
53.\" SUCH DAMAGE.
54.\"
55.\" $FreeBSD: src/lib/libpthread/man/pthread_cleanup_push.3,v 1.11 2002/09/16 19:29:28 mini Exp $
56.\"
57.Dd January 30, 2003
58.Dt PTHREAD_CLEANUP 3
59.Os
60.Sh NAME
61.Nm pthread_cleanup_push ,
62.Nm pthread_cleanup_pop
63.Nd add and remove cleanup functions for thread exit
64.Sh LIBRARY
65.Lb libpthread
66.Sh SYNOPSIS
67.In pthread.h
68.Ft void
69.Fn pthread_cleanup_push "void \*[lp]*cleanup_routine\*[rp]\*[lp]void *\*[rp]" "void *arg"
70.Ft void
71.Fn pthread_cleanup_pop "int execute"
72.Sh DESCRIPTION
73The
74.Fn pthread_cleanup_push
75function adds
76.Fa cleanup_routine
77to the top of the stack of cleanup handlers that
78get called when the current thread exits.
79.Pp
80The
81.Fn pthread_cleanup_pop
82function pops the top cleanup routine off of the current threads cleanup
83routine stack, and, if
84.Fa execute
85is non-zero, it will execute the function.
86.Pp
87When
88.Fa cleanup_routine
89is called, it is passed
90.Fa arg
91as its only argument.
92.Pp
93These functions may be implemented as macros which contain scope delimiters;
94therefore, there must be a matching
95.Fn pthread_cleanup_pop
96for every
97.Fn pthread_cleanup_push
98at the same level of lexical scoping.
99.Pp
100The effect of calling
101.Fn longjmp
102or
103.Fn siglongjmp
104is undefined after a call to
105.Fn pthread_cleanup_push
106but before the matching call to
107.Fn pthread_cleanup_pop
108after the jump buffer was filled.
109.Sh RETURN VALUES
110Neither
111.Fn pthread_cleanup_push
112nor
113.Fn pthread_cleanup_pop
114returns a value.
115.Sh ERRORS
116None.
117.Sh SEE ALSO
118.Xr pthread_exit 3
119.Sh STANDARDS
120.Fn pthread_cleanup_push
121and
122.Fn pthread_cleanup_pop
123conform to
124.St -p1003.1-96 .
125