xref: /openbsd-src/lib/libpthread/man/pthread_once.3 (revision 74493c911758b2183cc115e278709160d7712ec9)
1*74493c91Sd.\" $OpenBSD: pthread_once.3,v 1.7 1999/11/24 05:35:32 d Exp $
2a278733dSd.\" Copyright (c) 1996 John Birrell <jb@cimlogic.com.au>.
3a278733dSd.\" All rights reserved.
4a278733dSd.\"
5a278733dSd.\" Redistribution and use in source and binary forms, with or without
6a278733dSd.\" modification, are permitted provided that the following conditions
7a278733dSd.\" are met:
8a278733dSd.\" 1. Redistributions of source code must retain the above copyright
9a278733dSd.\"    notice, this list of conditions and the following disclaimer.
10a278733dSd.\" 2. Redistributions in binary form must reproduce the above copyright
11a278733dSd.\"    notice, this list of conditions and the following disclaimer in the
12a278733dSd.\"    documentation and/or other materials provided with the distribution.
13a278733dSd.\" 3. All advertising materials mentioning features or use of this software
14a278733dSd.\"    must display the following acknowledgement:
15a278733dSd.\"	This product includes software developed by John Birrell.
16a278733dSd.\" 4. Neither the name of the author nor the names of any co-contributors
17a278733dSd.\"    may be used to endorse or promote products derived from this software
18a278733dSd.\"    without specific prior written permission.
19a278733dSd.\"
20a278733dSd.\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
21a278733dSd.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22a278733dSd.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23a278733dSd.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24a278733dSd.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25a278733dSd.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26a278733dSd.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27a278733dSd.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28a278733dSd.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29a278733dSd.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30a278733dSd.\" SUCH DAMAGE.
31a278733dSd.\"
32*74493c91Sd.\" $FreeBSD: pthread_once.3,v 1.5 1999/08/28 00:03:09 peter Exp $
33*74493c91Sd.\"
34a278733dSd.Dd April 4, 1996
35a278733dSd.Dt PTHREAD_ONCE 3
36c043c0f7Sd.Os
37a278733dSd.Sh NAME
38a278733dSd.Nm pthread_once
39a278733dSd.Nd dynamic package initialization
40a278733dSd.Sh SYNOPSIS
41a278733dSd.Fd #include <pthread.h>
42a278733dSd.Pp
430ed0e350Sd.Ft pthread_once_t
44a278733dSd.Fa once_control
450ed0e350Sd\&=
460ed0e350Sd.Dv PTHREAD_ONCE_INIT ;
470ed0e350Sd.Pp
48a278733dSd.Ft int
49a278733dSd.Fn pthread_once "pthread_once_t *once_control" "void (*init_routine)(void)"
50a278733dSd.Sh DESCRIPTION
51a278733dSdThe first call to
52a278733dSd.Fn pthread_once
53a278733dSdby any thread in a process, with a given
54a278733dSd.Fa once_control ,
55a278733dSdwill call the
56a278733dSd.Fn init_routine
57a278733dSdwith no arguments. Subsequent calls to
58a278733dSd.Fn pthread_once
59a278733dSdwith the same
60a278733dSd.Fa once_control
61a278733dSdwill not call the
62a278733dSd.Fn init_routine .
63a278733dSdOn return from
64a278733dSd.Fn pthread_once ,
65a278733dSdit is guaranteed that
66a278733dSd.Fn init_routine
67a278733dSdhas completed. The
68a278733dSd.Fa once_control
69a278733dSdparameter is used to determine whether the associated initialization
70a278733dSdroutine has been called.
71a278733dSd.Pp
72a278733dSdThe function
73a278733dSd.Fn pthread_once
74a278733dSdis not a cancellation point. However, if
75a278733dSd.Fn init_routine
76a278733dSdis a cancellation point and is cancelled, the effect on
77a278733dSd.Fa once_control is as if
78a278733dSd.Fn pthread_once
79a278733dSdwas never called.
80a278733dSd.Pp
81a278733dSdThe constant
8202ecd0d2Saaron.Dv PTHREAD_ONCE_INIT
83a278733dSdis defined by header
84a278733dSd.Aq Pa pthread.h .
85a278733dSd.Pp
86a278733dSdThe behavior of
87a278733dSd.Fn pthread_once
88a278733dSdis undefined if
89a278733dSd.Fa once_control
90a278733dSdhas automatic storage duration or is not initialized by
9102ecd0d2Saaron.Dv PTHREAD_ONCE_INIT .
92a278733dSd.Sh RETURN VALUES
93a278733dSdIf successful,  the
94a278733dSd.Fn pthread_once
95a278733dSdfunction will return zero. Otherwise an error number will be returned to
96a278733dSdindicate the error.
97a278733dSd.Sh ERRORS
98a278733dSdNone.
99a278733dSd.Sh STANDARDS
100a278733dSd.Fn pthread_once
101a278733dSdconforms to ISO/IEC 9945-1 ANSI/IEEE
102a278733dSd.Pq Dq Tn POSIX
103a278733dSdStd 1003.1 Second Edition 1996-07-12.
104