pthread_key_create(3) Library Functions Manual pthread_key_create(3) pthread_key_create, pthread_key_delete, pthread_setspecific, pthread_getspecific - #include int pthread_key_create(pthread_key_t *key, typeof(void (void *)) *destr_function; int pthread_key_delete(pthread_key_t key); int pthread_setspecific(pthread_key_t key, const void *pointer); void * pthread_getspecific(pthread_key_t key); . . POSIX . TSD . TSD. TSD void * TSD. TSD TSD . TSD void * TSD TSD . TSD NULL . pthread_key_create() TSD . key. PTHREAD_KEYS_MAX . NULL . destr_function NULL . pthread_exit() destr_function . destr_function NULL. . NULL . NULL . NULL NULL . glibc PTHREAD_DESTRUCTOR_ITERATIONS NULL . . pthread_key_delete() TSD. NULL . pthread_setspecific() key pointer . pthread_getspecific() key . pthread_key_create() pthread_key_delete() pthread_setspecific() 0 . pthread_key_create() key. pthread_getspecific() key NULL . pthread_key_create() : EAGAIN PTHREAD_KEYS_MAX . pthread_key_delete() pthread_setspecific() : EINVAL key TSD . pthread_getspecific() NULL key TSD . pthread_create(3), pthread_exit(3), pthread_testcancel(3). 100 : /* Key for the thread-specific buffer */ static pthread_key_t buffer_key; /* Once-only initialisation of the key */ static pthread_once_t buffer_key_once = PTHREAD_ONCE_INIT; /* Allocate the thread-specific buffer */ void buffer_alloc(void) { pthread_once(&buffer_key_once, buffer_key_alloc); pthread_setspecific(buffer_key, malloc(100)); } /* Return the thread-specific buffer */ char * get_buffer(void) { return (char *) pthread_getspecific(buffer_key); } /* Allocate the key */ static void buffer_key_alloc() { pthread_key_create(&buffer_key, buffer_destroy); } /* Free the thread-specific buffer */ static void buffer_destroy(void * buf) { free(buf); } 3 . . : . 6.18 17 2025 pthread_key_create(3)