Open System Services System Calls Reference Manual (G06.25+, H06.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
H-series OSS processes: /G/system/zdllnnn/zsptdll
SYNOPSIS
#include <spthread.h>
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.
RETURN VALUES
If an error condition occurs, this function returns an integer value indicating the type of error.
Possible return values are:
0 Successful completion.
[EINVAL] The value specified for the once_control parameter is not valid.
STANDARDS CONFORMANCE
This function is an extension to the XPG4 Version 2 specification. Interfaces documented on this
reference page conform to the following industry standards:
• IEEE Std 1003.1c-1995, POSIX System Application Program Interface
The use of the header file spthread.h is an HP exception to the POSIX standard.
5−88 Hewlett-Packard Company 527186-003