Index of Section 2 Manual Pages
| Interix / SUA | pthread_setspecific.2 | Interix / SUA |
pthread_setspecific(2) pthread_setspecific(2)
pthread_getspecific()
NAME
pthread_getspecific(), pthread_setspecific() - get or set value by key
SYNOPSIS
#include
void * pthread_getspecific(pthread_key_t key);
int pthread_setspecific(pthread_key_t key, const void *value);
DESCRIPTION
The pthread_setspecific(2) function associates the value referenced by the
value argument to the key identified by the key argument. This association
is thread-specific; that is, different threads can associate different
values with the same key. Typically, these values are pointers to blocks
of dynamically allocated memory that are reserved for use by the thread.
The value specified by key must have been obtained from a call to the
pthread_key_create(2) function.
The pthread_getspecific(2) function returns the thread-specific value
associated with the specified key for the calling thread.
Both functions can be called from a thread's data-destructor functions.
Unless the value was changed by a call to pthread_setspecific() after a
data destructor had started, a call to pthread_getspecific for a key being
destroyed returns null.
RETURN VALUES
The pthread_getspecific() function returns the value associated with the
specified key; if no value is associated with that key, then the function
returns null.
On success, the pthread_setspecific() function returns 0; otherwise, an
error code is returned.
ERRORS
The pthread_setspecific() function can fail for the following reasons:
[ENOMEM]
Not enough memory is free to perform the operation.
[EINVAL]
The key argument does not refer to a valid key.
Neither function returns [EINTR].
SEE ALSO
pthread_key_create(2)
USAGE NOTES
All of these functions are thread safe.
None of these functions are async-signal safe.