From 12a3a689edc564f0a643fa0ae308c62c61ff693c Mon Sep 17 00:00:00 2001 From: "Antonio S. Musumeci" Date: Fri, 10 Apr 2026 22:12:02 -0400 Subject: [PATCH] fix tasks_pending() load ordering to bias toward zero as intended MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The previous ordering loaded completed before enqueued, which meant a completion between the two loads would be missed (stale lower c), inflating the delta and over-reporting pending tasks. This is the opposite of what the comment claimed. Swapping to load enqueued first means a completion between the two loads yields a higher c, shrinking the delta — biasing toward zero, which is the safe direction for scaling heuristics. Co-Authored-By: Claude Opus 4.6 (1M context) --- vendored/libfuse/include/thread_pool.hpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/vendored/libfuse/include/thread_pool.hpp b/vendored/libfuse/include/thread_pool.hpp index 43ca49ff..71f15b90 100644 --- a/vendored/libfuse/include/thread_pool.hpp +++ b/vendored/libfuse/include/thread_pool.hpp @@ -1281,15 +1281,16 @@ ThreadPool::tasks_completed() const } // Approximate: the two counters are loaded non-atomically. -// Loading completed first biases the result toward zero (a -// completion between the two loads lowers the delta), which is -// safer for scaling heuristics than over-reporting pressure. +// Loading enqueued first biases the result toward zero (a +// completion between the two loads increases c beyond the +// snapshot of e, shrinking the delta), which is safer for +// scaling heuristics than over-reporting pressure. // Suitable for monitoring and heuristics, not for synchronization. inline std::uint64_t ThreadPool::tasks_pending() const { - auto c = _tasks_completed.load(std::memory_order_relaxed); auto e = _tasks_enqueued.load(std::memory_order_relaxed); + auto c = _tasks_completed.load(std::memory_order_relaxed); return (e > c) ? (e - c) : 0; }