PTHREAD_SPECIFIC(3) BSD Programmer's Manual PTHREAD_SPECIFIC(3)NAME
pthread_setspecific, pthread_getspecific - thread specific data value
functions
SYNOPSIS
#include <pthread.h>
int
pthread_setspecific(pthread_key_t key, void *value);
void *
pthread_getspecific(pthread_key_t key);
DESCRIPTION
This interface is defined by IEEE Std1003.1c (``POSIX'').
The pthread_setspecific() and pthread_getspecific() functions maintain
thread-specific data values associated with data keys created by calling
pthread_key_create().
The pthread_setspecific() function associates the data value specified in
value with the data key key previously created by a call to
pthread_key_create(). While data keys are unique within the implementa-
tion the data values associated with them are maintained per-thread. The
intent is to allow creation of per-thread state for functions that re-
quire that local state be maintained.
The pthread_getspecific() function retrieves a data value previously reg-
istered with pthread_setspecific().
Calling pthread_setspecific() or pthread_getspecific() with a key value
not previously created with a call to pthread_key_create() results in un-
defined behavior.
RETURN VALUES
Upon successful completion, pthread_getspecific() returns the thread spe-
cific data value associated with key or a NULL to indicate that no
thread-specific data value is available.
Upon successful completion, the pthread_setspecific() function returns 0.
A non-zero result indicates that an error occurred.
ERRORS
The pthread_setspecific function may fail and return one of the following
errors:
[EINVAL] The key value is invalid.
[ENOMEM] Insufficient memory exists to associate the specified value
with key.
SEE ALSOpthreads(3), pthread_exit(3), pthread_key_create(3),
pthread_key_delete(3)STANDARDS
The pthread_setspecific and pthread_getspecific functions conform to IEEE
Std1003.1c (``POSIX'').
HISTORY
The pthread_setspecific and pthread_getspecific functions first appeared
in BSD/OS 3.0.
4th Berkeley Distribution June 3, 1996 1