Multithreaded Programming Guide


Use pthread_once(3T) to call an initialization routine the first time pthread_once(3T) is called. Subsequent calls to pthread_once() have no effect.

int	 pthread_once(pthread_once_t *once_control,
    void (*init_routine)(void));
#include <pthread.h>

pthread_once_t once_control = PTHREAD_ONCE_INIT;
int ret;

ret = pthread_once(&once_control, init_routine);

The once_control parameter determines whether the associated initialization routine has been called.

Return Values

pthread_once() returns zero after completing successfully. Any other returned value indicates that an error occurred. When the following condition occurs, pthread_once() fails and returns the corresponding value.


once_control or init_routine is NULL.