From e55bf1829bb68365b2ec7a58f5d150a9b2743a29 Mon Sep 17 00:00:00 2001 From: "Antonio S. Musumeci" Date: Sat, 18 Apr 2026 17:50:30 -0400 Subject: [PATCH] thread_pool: skip _remove_thread_scaling_locked during shutdown _add_thread_scaling_locked already bails out with -ECANCELED when _stop is set. Mirror that check in _remove_thread_scaling_locked so the monitor cannot enqueue a wakeup poison pill after shutdown begins. The pill would be benign (workers break on _stop before claiming), but it would sit in the queue until BoundedQueue is destroyed, and skipping it also avoids an unnecessary semaphore signal on the teardown path. --- vendored/libfuse/include/thread_pool.hpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/vendored/libfuse/include/thread_pool.hpp b/vendored/libfuse/include/thread_pool.hpp index 7a1f877a..d87cd415 100644 --- a/vendored/libfuse/include/thread_pool.hpp +++ b/vendored/libfuse/include/thread_pool.hpp @@ -1105,6 +1105,14 @@ inline int ThreadPool::_remove_thread_scaling_locked() { + // Skip once shutdown has begun. Mirrors _add_thread_scaling_locked's + // early return for symmetry and prevents the monitor from enqueuing + // wakeup pills that no worker will claim (workers see _stop and + // BREAK before reaching _try_claim_and_remove_self), which would + // leave stale pills in the queue until BoundedQueue is destroyed. + if(_stop.load(std::memory_order_acquire)) + return -ECANCELED; + // Hold _threads_mutex across both the size check and the // _remove_count increment so that a concurrent removal (idle // self-exit or another _remove_thread call) cannot shrink the