From 80af7ffcc08051607c25494b37e0a921dcdb5fb1 Mon Sep 17 00:00:00 2001 From: "Antonio S. Musumeci" Date: Fri, 10 Apr 2026 11:46:59 -0400 Subject: [PATCH] Drain _remove_count in destructor before sending poison pills MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If remove_thread() was called but no worker claimed the decrement before shutdown, _remove_count remains positive. Workers exiting via poison pills would enter the _remove_count CAS loop in _process_func, but since _stop is set, _remove_self is a no-op anyway. The stale counter is harmless at runtime but confusing when debugging — it suggests pending work that will never complete. Zero the counter after _stop is set and before enqueuing poison pills so the shutdown path is clean and unambiguous. Co-Authored-By: Claude Opus 4.6 (1M context) --- vendored/libfuse/include/thread_pool.hpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/vendored/libfuse/include/thread_pool.hpp b/vendored/libfuse/include/thread_pool.hpp index 7f483ad7..92a66648 100644 --- a/vendored/libfuse/include/thread_pool.hpp +++ b/vendored/libfuse/include/thread_pool.hpp @@ -317,6 +317,11 @@ ThreadPool::~ThreadPool() _name.c_str(), snapshot.size()); + // Drain any pending _remove_count so workers exiting via poison + // pills don't also try to detach themselves (which would be a + // no-op due to _stop, but avoids confusion in debugging). + _remove_count.store(0,std::memory_order_relaxed); + // Enqueue one poison pill per thread for(std::size_t i = 0; i < snapshot.size(); ++i) _queue.enqueue_unbounded(Func{});