pthread_once

Synopsis

#include <pthread.h>

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

Status

Implemented

Conformance

IEEE Std 1003.1-2017

Description

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

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

If the call to init_routine is terminated by a call to longjmp(), _longjmp(), or siglongjmp(), the behavior is undefined.

The constant PTHREAD_ONCE_INIT is defined in the <pthread.h> header.

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

Return value

Upon successful completion, pthread_once() shall return zero; otherwise, an error number shall be returned to indicate the error.

Errors

The pthread_once() function shall not return an error code of EINTR.

POSIX deviations

No POSIX deviations discovered.