From 22eb9daeb3100d4f635a3866646acacff3f189e5 Mon Sep 17 00:00:00 2001 From: afwerar <1296468573@qq.com> Date: Sun, 5 Sep 2021 13:53:33 +0800 Subject: [PATCH] [TD-6169]: windows dll client can not quit. --- src/util/src/tcache.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/util/src/tcache.c b/src/util/src/tcache.c index 3ab100acab..776a0ad9c8 100644 --- a/src/util/src/tcache.c +++ b/src/util/src/tcache.c @@ -71,7 +71,8 @@ static pthread_once_t cacheThreadInit = PTHREAD_ONCE_INIT; static pthread_mutex_t guard = PTHREAD_MUTEX_INITIALIZER; static SArray* pCacheArrayList = NULL; static bool stopRefreshWorker = false; -static bool refreshWorkerStopped = false; +static bool refreshWorkerNormalStopped = false; +static bool refreshWorkerUnexpectedStopped = false; static void doInitRefreshThread(void) { pCacheArrayList = taosArrayInit(4, POINTER_BYTES); @@ -538,9 +539,10 @@ void taosCacheCleanup(SCacheObj *pCacheObj) { pCacheObj->deleting = 1; // wait for the refresh thread quit before destroying the cache object. + // But in the dll, the child thread will be killed before atexit takes effect. while(atomic_load_8(&pCacheObj->deleting) != 0) { - if (refreshWorkerUnexpectedStopped) return; if (refreshWorkerNormalStopped) break; + if (refreshWorkerUnexpectedStopped) return; taosMsleep(50); } @@ -693,7 +695,6 @@ void* taosCacheTimedRefresh(void *handle) { const int32_t SLEEP_DURATION = 500; //500 ms int64_t count = 0; - atexit(taosCacheRefreshWorkerUnexpectedStopped); while(1) { @@ -774,6 +775,6 @@ void taosCacheRefresh(SCacheObj *pCacheObj, __cache_free_fn_t fp) { doCacheRefresh(pCacheObj, now, fp); } -void taosStopCacheRefreshWorker() { - stopRefreshWorker = false; +void taosStopCacheRefreshWorker(void) { + stopRefreshWorker = true; } \ No newline at end of file -- GitLab