NAME | SYNOPSIS | DESCRIPTION | RETURN VALUE | ERRORS | ATTRIBUTES | SEE ALSO
#include <pthread.h>int pthread_setspecific(pthread_key_t key, const void * value);
The pthread_setspecific function associates a thread-specific value with a key obtained via a previous call to pthread_key_create . Different threads may bind different values to the same key. These values are typically pointers to blocks of dynamically allocated memory that have been reserved for use by the calling thread.
The pthread_getspecific function returns the value currently bound to the specified key in the calling thread. This function is implemented as a macro. The effect of calling pthread_getspecific with a key value not obtained from pthread_key_create or after key has been deleted with pthread_key_delete is undefined.
Both pthread_setspecific and pthread_getspecific may be called, either explicitly or implicitly, from a thread-specific data destructor function. Calling pthread_setspecific from a destructor could result in lost storage.
The pthread_getspecific function returns the thread-specific data value associated with the given key . If no thread-specific data value is associated with key in the calling thread, the value NULL is returned.
Upon successful completion, pthread_setspecific returns zero. Otherwise, an error code is returned. (NOTE: errno is not set.)
The following error codes apply only to pthread_setspecific .
The key value is invalid.
There is nsufficient memory to associate the value with the key.
See attributes(5) for descriptions of the following attributes:
ATTRIBUTE TYPE | ATTRIBUTE VALUE |
---|---|
Interface Stability | Evolving |
NAME | SYNOPSIS | DESCRIPTION | RETURN VALUE | ERRORS | ATTRIBUTES | SEE ALSO