Here, TLS is the initialism of thread local storage.
pthread
1 2 3 4 5 6 | #include <pthread.h> int pthread_key_create (pthread_key_t *key, void (*destructor)(void *)); int pthread_key_delete (pthread_key_t key); int pthread_setspecific (pthread_key_t key, const void *value); void *pthread_getspecific (pthread_key_t key); int pthread_once(pthread_once_t *once_control, void (*init)(void)); |
gcc
1 | static __thread int buf[MAX_ERROR_LEN]; |
win32
1 2 3 4 5 6 7 8 9 10 11 12 | DWORD TlsAlloc(); BOOL TlsFree(DWORD dwTlsIndex); LPVOID TlsGetValue(DWORD dwTlsIndex); BOOL TlsSetValue(DWORD dwTlsIndex, LPVOID lpTlsValue); // or // in header, __declspec(thread) extern size_t strdupa_len; // and in c file, // as to one variable, __declspec(thread) should be write twice, // one in prefix of prototype, // one in prefix of definition __declspec(thread) size_t strdupa_len; |
refer to:
https://blog.csdn.net/vevenlcf/article/details/77882985
https://blog.csdn.net/linyt/article/details/51931737