The Single UNIX ® Specification, Version 2
Copyright © 1997 The Open Group

 NAME

pthread_once - dynamic package initialisation

 SYNOPSIS



#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, will call the init_routine() with no arguments. Subsequent calls of pthread_once() with the same once_control will not call the init_routine(). On return from pthread_once(), it is guaranteed that init_routine() has completed. The once_control parameter is used to determine whether the associated initialisation routine has been called.

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

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

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

 RETURN VALUE

Upon successful completion, pthread_once() returns zero. Otherwise, an error number is returned to indicate the error.

 ERRORS

No errors are defined.

The pthread_once() function will not return an error code of [EINTR].

 EXAMPLES

None.

 APPLICATION USAGE

None.

 FUTURE DIRECTIONS

None.

 SEE ALSO

<pthread,h>.

DERIVATION

Derived from the POSIX Threads Extension (1003.1c-1995)

UNIX ® is a registered Trademark of The Open Group.
Copyright © 1997 The Open Group
[ Main Index | XSH | XCU | XBD | XCURSES | XNS ]