pthread-key-create

How does pthread_key_t and the method pthread_key_create work?

偶尔善良 提交于 2019-11-30 14:00:52
I am having some trouble figuring out how pthread_key_t and pthread_key_create work. From my understand, each thread has TLS (thread local storage) and that a key is used to access the thread local storage. What I do not get is when a key is created, does every thread get to use it? Lets say Thread 0 creates key 0, can Thread 1 then use key 0? If Thread 1 used key 0, would it access its own TLS or Thread 0's TLS? Is there some global array or something that keeps track of all the keys being used? pthread_keys are just what you said, thread local storage referred to by a common key. So multiple

How does pthread_key_t and the method pthread_key_create work?

时光总嘲笑我的痴心妄想 提交于 2019-11-29 19:29:18
问题 I am having some trouble figuring out how pthread_key_t and pthread_key_create work. From my understand, each thread has TLS (thread local storage) and that a key is used to access the thread local storage. What I do not get is when a key is created, does every thread get to use it? Lets say Thread 0 creates key 0, can Thread 1 then use key 0? If Thread 1 used key 0, would it access its own TLS or Thread 0's TLS? Is there some global array or something that keeps track of all the keys being