pthread_setspecific(3T) SDK R4.11 pthread_setspecific(3T)
NAME
pthreadsetspecific, pthreadgetspecific - associate or retrieve a
thread-specific value for a key
SYNOPSIS
#include <pthread.h>
int pthreadsetspecific(pthreadkeyt key, void *value1);
int pthreadgetspecific(pthreadkeyt key, void **value2);
where:
key A process-wide, thread-specific data key
value1 A value to be associated with the key
value2 A pointer to the location to store the value associated with
the key
DESCRIPTION
The pthreadsetspecific() function associates a thread-specific value
with a process-wide key obtained via a previous call to
pthreadkeycreate(). Different threads may bind different values to
the same process-wide key. These values are typically pointers to
blocks of dynamically allocated memory that have been reserved for
use by the calling thread. Hence they are defined to have type (void
*).
The pthreadgetspecific() function returns the value currently bound
to the process-wide key on behalf of the calling thread. The value
is written into the location pointed to by value2. A value of NULL
is returned if the thread has never associated a value with the key.
This implies that newly created threads have NULL values for all
valid keys.
The effect of calling pthreadsetspecific() or pthreadgetspecific()
either explicitly or implicitly from a thread-specific data
destructor function is unspecified.
DIAGNOSTICS
Return Value
If successful, these functions return 0. Otherwise they return -1
and set errno to indicate the error.
If successful, pthreadgetspecific() stores the value currently bound
to the specified key into the location pointed to by value2.
Errors
For each of the following conditions, pthreadsetspecific() and
pthreadgetspecific() return -1 and set errno to the corresponding
value:
[EINVAL] The key is invalid. This occurs when the key does not
refer to an existing key created by a call to
pthreadkeycreate().
SEE ALSO
pthreadkeycreate(3T).
Licensed material--property of copyright holder(s)