| 1 |
.\" Copyright, Xavier Leroy <[email protected]> |
| 2 |
.\" Copyright 2023, Alejandro Colomar <[email protected]> |
| 3 |
.\" |
| 4 |
.\" SPDX-License-Identifier: Linux-man-pages-copyleft |
| 5 |
.\" |
| 6 |
.TH pthread_once 3 2024-05-02 "Linux man-pages 6.9.1" |
| 7 |
. |
| 8 |
. |
| 9 |
.SH NAME |
| 10 |
pthread_once |
| 11 |
\- |
| 12 |
once-only initialization |
| 13 |
. |
| 14 |
. |
| 15 |
.SH SYNOPSIS |
| 16 |
.B #include <pthread.h> |
| 17 |
.P |
| 18 |
.BI "pthread_once_t " once_control " = PTHREAD_ONCE_INIT;" |
| 19 |
.P |
| 20 |
.BI "int pthread_once(pthread_once_t *" once_control ", void (*" init_routine ") (void));" |
| 21 |
. |
| 22 |
. |
| 23 |
.SH DESCRIPTION |
| 24 |
The purpose of \fBpthread_once\fP is |
| 25 |
to ensure that a piece of initialization code is executed at most once. |
| 26 |
The \fIonce_control\fP argument points to a static or extern variable |
| 27 |
statically initialized to \fBPTHREAD_ONCE_INIT\fP. |
| 28 |
.P |
| 29 |
The first time \fBpthread_once\fP is called |
| 30 |
with a given \fIonce_control\fP argument, |
| 31 |
it calls \fIinit_routine\fP with no argument |
| 32 |
and changes the value of the \fIonce_control\fP variable |
| 33 |
to record that initialization has been performed. |
| 34 |
Subsequent calls to \fBpthread_once\fP |
| 35 |
with the same \fBonce_control\fP argument |
| 36 |
do nothing. |
| 37 |
. |
| 38 |
. |
| 39 |
.SH "RETURN VALUE" |
| 40 |
\fBpthread_once\fP always returns 0. |
| 41 |
. |
| 42 |
. |
| 43 |
.SH ERRORS |
| 44 |
None. |