Open System Services System Calls Reference Manual (G06.29+, H06.08+, J06.03+)
pthread_once(2) OSS System Calls Reference Manual
NAME
pthread_once - Calls a routine to be executed once by a single thread
LIBRARY
G-series native OSS processes: /G/system/sysnn/zsptsrl
32-bit H-series and J-series OSS processes that use the POSIX User Thread Model library:
/G/system/zdllnnn/zputdll
64-bit H-series and J-series OSS processes that use the POSIX User Thread Model library:
/G/system/zdllnnn/yputdll
H-series and J-series OSS processes that use the Standard POSIX Threads library:
/G/system/zdllnnn/zsptdll
SYNOPSIS
#include <pthread.h> | #include <spthread.h>
/* pthread.h is required to use POSIX User Thread Model library */
/* spthread.h is required to use Standard POSIX Threads library */
pthread_once_t once_control = PTHREAD_ONCE_INIT;
int pthread_once(
pthread_once_t *once_control,
void (*routine)(void));
PARAMETERS
once_control Specifies a block that controls the one-time execution code. Each one-time exe-
cution routine must have its own unique pthread_once_t block.
routine Specifies the address of the routine to be executed once. This routine is called
only once, regardless of the number of times it and its associated once_control
block are passed to pthread_once().
DESCRIPTION
The first call to this function by any thread in a process with a given once_control block calls the
routine specified by routine with no arguments. Subsequent calls to pthread_once() with the
same once_control block do not call the routine. On return from pthread_once(), the routine is
guaranteed to have finished.
For example, a mutex or a per-thread context key must be created exactly once. Calling
pthread_once() ensures that the initialization is serialized across multiple threads. Other
threads that reach the same point in the code are delayed until the first thread is finished.
To initialize the once_control block, use the PTHREAD_ONCE_INIT macro, as shown in the
SYNOPSIS.
On systems running H06.21 or later H-series RVUs or J06.10 or later J-series RVUs, you can use
either the POSIX User Thread Model library or the Standard POSIX Threads library for threaded
applications.
To use this function in a threaded application that uses the POSIX User Thread Model library on
systems running H06.21 or later RVUs or J06.10 or later RVUs, you must perform all of the fol-
lowing tasks:
• Include the pthread.h header file in the application.
• Compile the application using the _PUT_MODEL_ feature test macro or equivalent
compiler command option.
• Link the application to the zputdll library (/G/system/zdllnnn/zputdll).
5−162 Hewlett-Packard Company 527186-023