qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v2 1/4] util/thread-pool: Fix thread pool freeing locking


From: Nicolas Saenz Julienne
Subject: [PATCH v2 1/4] util/thread-pool: Fix thread pool freeing locking
Date: Thu, 3 Mar 2022 15:58:19 +0100

Upon freeing a thread pool we need to get rid of any remaining worker.
This is achieved by setting the thread pool's topping flag, waking the
workers up, and waiting for them to exit one by one. The problem is that
currently all this process happens with the thread pool lock held,
effectively blocking the workers from exiting.

So let's release the thread pool lock after signaling a worker thread
that it's time to exit to give it a chance to do so.

Fixes: f7311ccc63 ("threadpool: add thread_pool_new() and thread_pool_free()")
Signed-off-by: Nicolas Saenz Julienne <nsaenzju@redhat.com>
---
 util/thread-pool.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/util/thread-pool.c b/util/thread-pool.c
index d763cea505..fdb43c2d3b 100644
--- a/util/thread-pool.c
+++ b/util/thread-pool.c
@@ -339,7 +339,9 @@ void thread_pool_free(ThreadPool *pool)
     pool->stopping = true;
     while (pool->cur_threads > 0) {
         qemu_sem_post(&pool->sem);
+        qemu_mutex_unlock(&pool->lock);
         qemu_cond_wait(&pool->worker_stopped, &pool->lock);
+        qemu_mutex_lock(&pool->lock);
     }
 
     qemu_mutex_unlock(&pool->lock);
-- 
2.35.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]