Pthread_key_t and pthread_once_t?

Starting with pthreads, I can’t understand what is business with pthread_key_t and pthread_once_t?

Can someone explain in simple terms with examples, if possible?

thanks

+3
source share
3 answers

No, this cannot be explained in unprofessional conditions. Schedulers cannot successfully program using pthreads in C ++. Requires a specialist known as a "computer programmer" :-)

pthread_once_t - , pthread_once , , , . init , , , , . , - . , , . pthread_once , , , , ( , - pthread_once, , (, , ), . ).

pthread_key_t - . . TLS, pthread_key_create . , TLS . , TLS , , , TLS, , TLS . pthread , , 0 , pthread_key_create, 1 ..

+9

pthread_key_t - : , ( -, ) . TLS . . pthread_getspecific .

pthread_once_t - pthread_once. , , . , , , - , . - pthread_once(), , , , , . pthread_once(), .

+10

, .

pthread_once_t pthread_once(). pthread_once(&s, fn) fn , s, . pthread_once() - noops. .

pthread_once_tinitialize to PTHREAD_ONCE_INIT.

+2
source

Source: https://habr.com/ru/post/1714311/


All Articles