Name

pthread_getspecific
- get a thread-specific data value

Library

libc_r.lib libpthread.lib libthr.lib

Synopsis

  #include <pthread.h>
  void * pthread_getspecific (pthread_key_t key);

Return values

The pthread_getspecific function will return the thread-specific data value associated with the given key. If no thread-specific data value is associated with key, then the value NULL is returned.

Detailed description

The pthread_getspecific function returns the value currently bound to the specified key on behalf of the calling thread.

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.

The pthread_getspecific function may be called from a thread-specific data destructor function.


Examples

pthread_key_t keys;
 void* rc;
if(pthread_key_create(&keys, NULL) != 0)
{
   printf("Error: pthread_key_create() failed0);
   return -1;
} else
{
   if(pthread_setspecific(keys, (void *)(long)(100)) != 0)
   {
    printf("Error: pthread_setspecific() failed\n");
    return -1;
   }
}
rc = pthread_getspecific(keys);
if(rc != (void *)(long)(100))
{
   printf("getspecific failed \n");
   return -1;
}

         

Errors

None.

See also

pthread_key_create, pthread_key_delete, pthread_setspecific


Feedback

For additional information or queries on this page send feedback

© 2005-2007 Nokia

Top