thread-specific-storage

pthread_key_create destructor not getting called

杀马特。学长 韩版系。学妹 提交于 2020-05-12 12:06:09
问题 As per pthread_key_create man page we can associate a destructor to be called at thread shut down. My problem is that the destructor function I have registered is not being called. Gist of my code is as follows. static pthread_key_t key; static pthread_once_t tls_init_flag = PTHREAD_ONCE_INIT; void destructor(void *t) { // thread local data structure clean up code here, which is not getting called } void create_key() { pthread_key_create(&key, destructor); } // This will be called from every

Thread Specific Data vs Thread Local Storage

假装没事ソ 提交于 2019-11-29 07:45:56
问题 I've read Kerrisk's The Linux Programming Interface: A Linux and UNIX System Programming Handbook, Chapter 31 on Threads. The chapter include Thread Specific Data (Section 31.3.4) and Thread Local Storage (Section 31.4). The topics were covered on pages 663-669. Thread Specific Data ( pthread_key_create , pthread_setspecific , pthread_getspecific , and friends) looks more powerful, but appears to be a little more cumbersome to use, and appears to use the memory manager more frequently. Thread