tail head cat sleep
QR code linking to this page

Manual Pages  — PTHREAD_ONCE


pthread_once – dynamic package initialization



POSIX Threads Library (libpthread, -lpthread)


#include <pthread.h>

pthread_once_t once_control = PTHREAD_ONCE_INIT;
pthread_once(pthread_once_t *once_control, void (*init_routine)(void));


The first call to pthread_once() by any thread in a process, with a given once_control, will call the init_routine() with no arguments. Subsequent calls to pthread_once() with the same once_control will not call the init_routine(). On return from pthread_once(), it is guaranteed that init_routine() has completed. The once_control parameter is used to determine whether the associated initialization routine has been called.

The function pthread_once() is not a cancellation point. However, if init_routine() is a cancellation point and is cancelled, the effect on once_control is as if pthread_once() was never called.

The constant PTHREAD_ONCE_INIT is defined by header <pthread.h>.

The behavior of pthread_once() is undefined if once_control has automatic storage duration or is not initialized by PTHREAD_ONCE_INIT.


If successful, the pthread_once() function will return zero. Otherwise an error number will be returned to indicate the error.




The pthread_once() function conforms to IEEE Std 1003.1-96 ("POSIX.1").

PTHREAD_ONCE (3) April 4, 1996

tail head cat sleep
QR code linking to this page

Please direct any comments about this manual page service to Ben Bullock. Privacy policy.

Ken Thompson has an automobile which he helped design. Unlike most automobiles, it has neither speedometer, nor gas gauge, nor any of the other numerous idiot lights which plague the modern driver. Rather, if the driver makes a mistake, a giant “?” lights up in the center of the dashboard. “The experienced driver,” says Thompson, “will usually know what's wrong.”