From 44addf6bafc26515e41ca6267c88ae6dbe6c70ea Mon Sep 17 00:00:00 2001 From: xilai Date: Wed, 19 Feb 2025 11:37:58 +0800 Subject: [PATCH] =?UTF-8?q?cm=5Fdestroy=5Fthread=5Fpool=20=E4=BC=98?= =?UTF-8?q?=E5=8C=96=EF=BC=9A=E6=89=B9=E9=87=8F=E6=A0=87=E8=AE=B0=E7=BA=BF?= =?UTF-8?q?=E7=A8=8B=E5=85=B3=E9=97=AD=EF=BC=8C=E6=8F=90=E5=8D=87=E9=94=80?= =?UTF-8?q?=E6=AF=81=E7=BA=BF=E7=A8=8B=E6=B1=A0=E7=9A=84=E6=95=88=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cm_concurrency/cm_thread_pool.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/cm_concurrency/cm_thread_pool.c b/src/cm_concurrency/cm_thread_pool.c index 7235671..2d5736a 100644 --- a/src/cm_concurrency/cm_thread_pool.c +++ b/src/cm_concurrency/cm_thread_pool.c @@ -135,7 +135,7 @@ status_t cm_create_thread_pool(cm_thread_pool_t *pool, uint32 thread_stack_size, void cm_destroy_thread_pool(cm_thread_pool_t *pool) { uint32 i; - pooling_thread_t *obj = NULL; + thread_t *thread = NULL; if (pool->starts == 0) { CM_FREE_PROT_PTR(pool->threads); @@ -144,8 +144,20 @@ void cm_destroy_thread_pool(cm_thread_pool_t *pool) cm_thread_lock(&pool->lock); for (i = 0; i < pool->starts; ++i) { - obj = &pool->threads[i]; - cm_close_thread(&obj->thread); + thread = &pool->threads[i].thread; + thread->closed = CM_TRUE; + } + for (i = 0; i < pool->starts; ++i) { + thread = &pool->threads[i].thread; +#ifdef WIN32 + WaitForSingleObject(thread->handle, INFINITE); +#else + void *ret = NULL; + if (thread->id != 0) { + (void)pthread_join(thread->id, &ret); + thread->id = 0; + } +#endif } cm_thread_unlock(&pool->lock); -- Gitee