pthread_setspecific Subroutine Purpose Sets the thread-specific data associated with a specified key. Library Threads Library (libpthreads.a) Syntax #include
int pthread_setspecific (key, value) pthread_key_t key; const void *value; Description The pthread_setspecific subroutine sets the thread-specific data associated with the key key. It is a void pointer. Typically, thread-specific data are pointers to dynamically allocated storage. When freeing the storage, the value should be set to NULL. It is not recommended to cast this pointer into scalar data type (int for example), because the casts may not be portable, and because the value of NULL is implementation-dependent. Note: The pthread.h header file must be the first included file of each source file using the threads library. Parameters key Specifies the key to which the value is bound. value Specifies the new thread-specific value. Return Values Upon successful completion, 0 is returned. Otherwise, an error code is returned. Error Codes The pthread_setspecific subroutine is unsuccessful if the following is true: EINVAL The key parameter is not valid. ENOMEM There is not sufficient memory to associate the value with the key. Implementation Specifics This subroutine is part of the Base Operating System (BOS) Runtime. Related Information The pthread_key_create subroutine, pthread_getspecific subroutine. Thread-Specific Data. Threads Library Quick Reference.