pthreadkeycreate
pthread_key_create is a function in the POSIX threading API that allocates a key for thread-specific data. A key is global to the process; each thread can associate a distinct value with the key using pthread_setspecific, and retrieve it with pthread_getspecific. The value associated with a key is stored per thread, so threads do not share per-thread data via that key.
The function prototype is int pthread_key_create(pthread_key_t *key, void (*destructor)(void *)); On success, it writes the new key
If the destructor parameter is non-NULL, the destructor is invoked for each thread that has a non-NULL
Destroying a key with pthread_key_delete also triggers destructor calls for existing non-NULL per-thread values for that
See also: pthread_getspecific, pthread_setspecific, pthread_key_delete, and POSIX threads.