On Thu, May 21, 2026 at 09:06:07PM +0200, Maciej S. Szmigiero wrote:
> From: "Maciej S. Szmigiero" <[email protected]>
>
> thread_pool_adjust_max_threads_to_work() is supposed to give each task its
> own thread by setting the pool max thread count limit accordingly.
>
> However, if there aren't any tasks currently in the pool the pool max
> thread count will be set to 0, which will trigger an assertion failure
> in thread_pool_set_max_threads() - because setting this value would
> completely block the pool by not allowing it to process any submitted
> tasks.
>
> This also can happen if a task is submitted via
> thread_pool_submit_immediate() to an empty pool but the task completes so
> quickly that by the time this function calls
> thread_pool_adjust_max_threads_to_work() the pool again has no unfinished
> tasks in it.
Sorry for a late comment. Just curious: how easy is this to reproduce?
>
> Fix this by making sure that the pool is allowed to create at least 1
> thread.
But then it means we have no work and then we will create one thread does
nothing..
I suspect the real culprit is we released the cur_work_lock during the
whole process of thread_pool_submit_immediate(). If we take it during the
whole window this will be a no-issue too.
The other question is, if it is awkward to manually adjust num of threads,
shall we set num to be -1 (unlimited) while pool created?
Thanks,
>
> Fixes: b5aa74968b27 ("thread-pool: Implement generic (non-AIO) pool support")
> Signed-off-by: Maciej S. Szmigiero <[email protected]>
> ---
> util/thread-pool.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/util/thread-pool.c b/util/thread-pool.c
> index 8f8cb38d5ce0..4e75191c983e 100644
> --- a/util/thread-pool.c
> +++ b/util/thread-pool.c
> @@ -493,5 +493,5 @@ bool thread_pool_adjust_max_threads_to_work(ThreadPool
> *pool)
> {
> QEMU_LOCK_GUARD(&pool->cur_work_lock);
>
> - return thread_pool_set_max_threads(pool, pool->cur_work);
> + return thread_pool_set_max_threads(pool, MAX(pool->cur_work, 1));
> }
>
--
Peter Xu