From: Nicolas Saenz Julienne <nsaenzju@redhat.com>
To: kwolf@redhat.com, stefanha@redhat.com, berrange@redhat.com
Cc: fam@euphon.net, eduardo@habkost.net, qemu-block@nongnu.org,
michael.roth@amd.com, mtosatti@redhat.com, qemu-devel@nongnu.org,
armbru@redhat.com, hreitz@redhat.com, pbonzini@redhat.com,
Nicolas Saenz Julienne <nsaenzju@redhat.com>,
eblake@redhat.com
Subject: [PATCH v2 1/4] util/thread-pool: Fix thread pool freeing locking
Date: Thu, 3 Mar 2022 15:58:19 +0100 [thread overview]
Message-ID: <20220303145822.518887-2-nsaenzju@redhat.com> (raw)
In-Reply-To: <20220303145822.518887-1-nsaenzju@redhat.com>
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
next prev parent reply other threads:[~2022-03-03 14:59 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-03 14:58 [PATCH v2 0/4] util/thread-pool: Expose minimun and maximum size Nicolas Saenz Julienne
2022-03-03 14:58 ` Nicolas Saenz Julienne [this message]
2022-03-10 9:20 ` [PATCH v2 1/4] util/thread-pool: Fix thread pool freeing locking Stefan Hajnoczi
2022-03-10 10:09 ` Nicolas Saenz Julienne
2022-03-03 14:58 ` [PATCH v2 2/4] Introduce event-loop-base abstract class Nicolas Saenz Julienne
2022-03-10 10:25 ` Stefan Hajnoczi
2022-03-11 10:17 ` Nicolas Saenz Julienne
2022-03-14 13:33 ` Stefan Hajnoczi
2022-03-14 13:34 ` Nicolas Saenz Julienne
2022-03-03 14:58 ` [PATCH v2 3/4] util/main-loop: Introduce the main loop into QOM Nicolas Saenz Julienne
2022-03-10 10:27 ` Stefan Hajnoczi
2022-03-03 15:13 ` [PATCH v2 4/4] util/event-loop-base: Introduce options to set the thread pool size Nicolas Saenz Julienne
2022-03-10 10:45 ` Stefan Hajnoczi
2022-03-11 10:40 ` Nicolas Saenz Julienne
2022-03-14 13:35 ` Stefan Hajnoczi
2022-03-14 17:19 ` Nicolas Saenz Julienne
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220303145822.518887-2-nsaenzju@redhat.com \
--to=nsaenzju@redhat.com \
--cc=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=eblake@redhat.com \
--cc=eduardo@habkost.net \
--cc=fam@euphon.net \
--cc=hreitz@redhat.com \
--cc=kwolf@redhat.com \
--cc=michael.roth@amd.com \
--cc=mtosatti@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).