| 1 |
.\" Copyright, the authors of the Linux man-pages project |
| 2 |
.\" |
| 3 |
.\" SPDX-License-Identifier: Linux-man-pages-copyleft |
| 4 |
.\" |
| 5 |
.TH pthread_once 3 2025-05-17 "Linux man-pages 6.18" |
| 6 |
. |
| 7 |
. |
| 8 |
.SH NAME |
| 9 |
pthread_once |
| 10 |
\- |
| 11 |
once-only initialization |
| 12 |
. |
| 13 |
. |
| 14 |
.SH SYNOPSIS |
| 15 |
.B #include <pthread.h> |
| 16 |
.P |
| 17 |
.BI "pthread_once_t " once_control " = PTHREAD_ONCE_INIT;" |
| 18 |
.P |
| 19 |
.BI "int pthread_once(pthread_once_t *" once_control ", typeof(void (void)) *" init_routine ; |
| 20 |
. |
| 21 |
. |
| 22 |
.SH DESCRIPTION |
| 23 |
The purpose of |
| 24 |
.BR pthread_once () |
| 25 |
is |
| 26 |
to ensure that a piece of initialization code is executed at most once. |
| 27 |
The |
| 28 |
.I once_control |
| 29 |
argument points to a static or extern variable |
| 30 |
statically initialized to |
| 31 |
.BR PTHREAD_ONCE_INIT . |
| 32 |
.P |
| 33 |
The first time |
| 34 |
.BR pthread_once () |
| 35 |
is called |
| 36 |
with a given |
| 37 |
.I once_control |
| 38 |
argument, |
| 39 |
it calls |
| 40 |
.I init_routine |
| 41 |
with no argument |
| 42 |
and changes the value of the |
| 43 |
.I once_control |
| 44 |
variable |
| 45 |
to record that initialization has been performed. |
| 46 |
Subsequent calls to |
| 47 |
.BR pthread_once () |
| 48 |
with the same |
| 49 |
.I once_control |
| 50 |
argument |
| 51 |
do nothing. |
| 52 |
. |
| 53 |
. |
| 54 |
.SH "RETURN VALUE" |
| 55 |
.BR pthread_once () |
| 56 |
always returns 0. |
| 57 |
. |
| 58 |
. |
| 59 |
.SH ERRORS |
| 60 |
None. |