// gcc -g -O0 -fPIC -shared -o libthreadfunc.so tls_func.c -lpthread #include #include #include #include #include #define TLS_SIZE 8192UL static __thread char g_sArray[TLS_SIZE ] ; void* thread_func(void* arg) { pthread_t tid = pthread_self(); memset(g_sArray, 0, sizeof(g_sArray)); snprintf(g_sArray, sizeof(g_sArray), "Thread ID: %lu", (unsigned long)tid); printf("g_sArray:%s\n", g_sArray); pthread_detach(pthread_self()); return NULL; }