Professional Multicore Programming: Design and Implementation for C++ Developers
by Cameron Hughes, Tracey Hughes
Name
NAME
pthread_once — dynamic package initialization
SYNOPSIS
THR #include <pthread.h>
int pthread_once (pthread_once_t *once_control,
void (*init_routine) (void));
pthread_once_t once_control = PTHREAD_ONCE_INIT;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 cancelation point. However, if init_routine is a cancelation point and is canceled, the effect on once_control shall be as if pthread_once() was never called.
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 may fail if:
[EINVAL] | If either once_control or init_routine is invalid. |
The pthread_once() function shall not return an error code of [EINTR].
EXAMPLES
None.
APPLICATION USAGE
None.
RATIONALE
Some C libraries are designed for dynamic initialization. That is, the global initialization for the library is performed ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access