diff --git a/samgr/adapter/posix/thread_adapter.c b/samgr/adapter/posix/thread_adapter.c index adf7cb353beb5bc785f816e9d6f74441d48aa598..b3da8208c5163f00d595e669ec245c07c48cd934 100644 --- a/samgr/adapter/posix/thread_adapter.c +++ b/samgr/adapter/posix/thread_adapter.c @@ -98,10 +98,16 @@ int THREAD_Total(void) void *THREAD_GetThreadLocal(void) { + if (g_localKey == -1) { + (void) pthread_once(&g_localKeyOnce, KeyCreate); + } return pthread_getspecific(g_localKey); } void THREAD_SetThreadLocal(const void *local) { + if (g_localKey == -1) { + (void) pthread_once(&g_localKeyOnce, KeyCreate); + } pthread_setspecific(g_localKey, local); }