From 96824eab313a9fbfbd7c3a0c7f8903a00ac7ee41 Mon Sep 17 00:00:00 2001 From: "Antonio S. Musumeci" Date: Thu, 9 Apr 2026 23:40:47 -0400 Subject: [PATCH] Document _tl_should_exit protocol in worker loops The _tl_should_exit mechanism in start_routine (and start_routine_autoscale) is correct but the control flow is non-obvious: _remove_thread_scaling_locked enqueues a lambda that sets the thread-local flag and calls _remove_self (detach + erase), then the worker checks the flag after running the func and exits. Replace the terse one-line comments with an explanation of the full protocol so future readers don't mistake it for dead code. Co-Authored-By: Claude Opus 4.6 (1M context) --- vendored/libfuse/include/thread_pool.hpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/vendored/libfuse/include/thread_pool.hpp b/vendored/libfuse/include/thread_pool.hpp index 0257a2d3..9bdfef56 100644 --- a/vendored/libfuse/include/thread_pool.hpp +++ b/vendored/libfuse/include/thread_pool.hpp @@ -375,7 +375,11 @@ ThreadPool::start_routine(void *arg_) btp->_tasks_completed.fetch_add(1,std::memory_order_relaxed); - // Check if _remove_thread_scaling_locked told us to exit + // _remove_thread_scaling_locked enqueues a lambda that sets + // _tl_should_exit and calls _remove_self (which detaches + + // erases from _threads). The lambda runs as normal work above, + // so we check the flag here. The thread has already been + // detached by _remove_self, so we just return. if(_tl_should_exit) { _tl_should_exit = false; @@ -459,7 +463,7 @@ ThreadPool::start_routine_autoscale(void *arg_) btp->_tasks_completed.fetch_add(1,std::memory_order_relaxed); - // Check if _remove_thread_scaling_locked told us to exit + // See comment in start_routine for the _tl_should_exit protocol. if(_tl_should_exit) { _tl_should_exit = false;