The pthread_key_create function

Name

pthread_key_create -- 

Synopsis

#include <pthread.h>

int pthread_key_create (pthread_key_t *key, void (*destructor) ());

Description

The pthread_key_create function create a new key that is visible to all threads. This key can be used with pthread_setspecific and pthread_getspecific to save and retrieve data associated with the a thread. If the function destructor is not NULL, then when a thread terminates, the destructor function will be called with the value associated with the key as the argument.

Returns

The pthread_key_create function returns 0 if successful. Otherwise it will return -1 and set errno to ENOMEM.

Implementation Notes

The value of POSIX_DATA KEYS_MAX is 8.

See Also

The pthread_getspecific function
The pthread_setspecific function