#include <pthread.h>
int
pthread_once
(pthread_once_t * once_control , void (*init_routine)
(void) );
The pthread_once function ensure the function init_routine runs only once regardless of how many threads call it. The thread that makes the first call to pthread_once succeeds in the call. Subsequent calls from other threads fail.
The pthread_once function returns zero.
None.
#include <pthread.h>
pthread_t pthread_self
( );
The pthread_self function returns a pointer to the calling thread.
The pthread_self function returns the pointer.
None.
#include <pthread.h>
int
pthread_key_create
(pthread_key_t * key , void (*destructor) ()
);
The pthread_key_create function create a new key that is visible to all threads. This key can be used with pthread_setspecific and pthread_getspecific to save and retrieve data associated with the a thread. If the function destructor is not NULL, then when a thread terminates, the destructor function will be called with the value associated with the key as the argument.
The pthread_key_create function returns 0 if successful. Otherwise it will return -1 and set errno to ENOMEM.
The value of POSIX_DATA KEYS_MAX is 8.
Section 14.8.4 |
Section 14.8.5 |
#include <pthread.h>
any_t
pthread_getspecific
(pthread_key_t key );
The pthread_getspecific function retrieves the value of a data key for the current thread. If key is not a valid key, then errno is set to EINVAL.
The pthread_getspecific function returns the value associated with key, or returns NULL if key is invalid.
None.
#include <pthread.h>
int
pthread_setspecific
(pthread_key_t key , any_t
value );
The pthread_setspecific function associates a value with a data key for the calling thread.
The pthread_setspecific function returns zero if the call is successful, otherwise it sets errno to EINVAL and returns -1.
None.
#include <pthread.h>
int
pthread_cleanup_push
(void (*fun) (), any_t
arg, cleanup_t new );
The pthread_cleanup_push function places the given function on the top of the thread's cleanup stack.
The pthread_cleanup_push function returns zero if the call is successful, otherwise it sets errno to EINVAL and returns -1.
None.
#include <pthread.h>
int
pthread_cleanup_pop
(int execute );
The pthread_cleanup_pop function pops a function off current thread's cleanup stack and if execute is non-zero, executes the function with the argument given in the corresponding call to pthread_cleanup_push.
The pthread_cleanup_pop function returns zero if the call is successful, otherwise it sets errno to EINVAL and returns -1.
None.