From 20acdfce196bbc0340a4b62be1842f6833905d49 Mon Sep 17 00:00:00 2001 From: "Antonio S. Musumeci" Date: Fri, 10 Apr 2026 01:03:49 -0400 Subject: [PATCH] Log actual thread count after hill-climb scaling The monitor thread read the thread count before calling add_thread or remove_thread, then logged count+1 or count-1 as the new size. If concurrent scaling (fast-path grow, idle self-exit) changed the count between the read and the action, the logged value was wrong. Read thread_count() after the scaling action for the log message so it reflects reality. The pre-action read is kept for the bounds check (direction guard) since that only needs to be approximately correct. Co-Authored-By: Claude Opus 4.6 (1M context) --- vendored/libfuse/include/thread_pool.hpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/vendored/libfuse/include/thread_pool.hpp b/vendored/libfuse/include/thread_pool.hpp index cd6ea21a..5aadde0a 100644 --- a/vendored/libfuse/include/thread_pool.hpp +++ b/vendored/libfuse/include/thread_pool.hpp @@ -534,12 +534,6 @@ ThreadPool::monitor_routine(void *arg_) continue; } - std::size_t count; - { - mutex_lockguard(btp->_threads_mutex); - count = btp->_threads.size(); - } - // Hill-climb: did smoothed throughput improve since last sample? if(ema_throughput >= prev_ema) { @@ -568,6 +562,9 @@ ThreadPool::monitor_routine(void *arg_) continue; } + // Read count, act, then re-read for an accurate log message. + std::size_t count = btp->thread_count(); + if(direction > 0 && count < btp->_scaling_config.max_threads) { btp->add_thread(); @@ -577,7 +574,7 @@ ThreadPool::monitor_routine(void *arg_) "threadpool (%s): hill-climb grow to %zu threads " "(ema %.1f -> %.1f)", btp->_name.c_str(), - count + 1, + btp->thread_count(), prev_ema, ema_throughput); } @@ -590,7 +587,7 @@ ThreadPool::monitor_routine(void *arg_) "threadpool (%s): hill-climb shrink to %zu threads " "(ema %.1f -> %.1f)", btp->_name.c_str(), - count - 1, + btp->thread_count(), prev_ema, ema_throughput); }