mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-10-26 19:01:56 -04:00
_remove_thread_scaling_locked previously enqueued a heap-allocated lambda (capturing a shared_ptr<promise>) to signal a specific worker to exit. This had two problems: 1. Bug: if the 5-second future::wait_for timed out, the function returned -EBUSY but the lambda remained in the queue. When a worker eventually executed it, it would unconditionally set _tl_should_exit and call _remove_self, silently killing an arbitrary thread with no compensating add. 2. Held _scaling_mutex for up to 5 seconds while blocking on the future, serializing all concurrent scaling operations (add_thread, remove_thread, _maybe_grow_on_pressure, monitor hill-climb). Replace the entire mechanism with an atomic _remove_count counter. _remove_thread_scaling_locked simply increments the counter and returns immediately. After each task, _process_func does a CAS-decrement; the winning worker detaches itself via _remove_self and exits. This eliminates: - All heap allocations (shared_ptr, promise, lambda captures) - The thread-local _tl_should_exit flag - The 5-second blocking window under _scaling_mutex - The stale-lambda bug entirely (no lambda to go stale) - The <memory> include (no longer needed) During shutdown, _remove_self is a no-op (_stop is set), so a worker that wins the CAS stays in _threads and is joined normally by the destructor. Any outstanding _remove_count credits are harmlessly abandoned. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> |
||
|---|---|---|
| .. | ||
| acutest | ||
| boost | ||
| CLI11 | ||
| fmt | ||
| khash | ||
| libfuse | ||
| nonstd | ||
| rapidhash | ||
| scope_guard | ||
| subprocess | ||