Document tasks_pending() as an approximate metric

tasks_pending() reads _tasks_enqueued and _tasks_completed in two
separate relaxed loads. Between the loads, additional tasks can
complete, making the result transiently inconsistent (the (e > c)
guard prevents underflow but not staleness).

Add a comment clarifying that this is intentionally approximate and
should not be used for synchronization decisions.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Antonio S. Musumeci 2026-04-09 23:43:43 -04:00
parent db784e00a2
commit c2da86d6da

View file

@ -1052,6 +1052,10 @@ ThreadPool::tasks_completed() const
return _tasks_completed.load(std::memory_order_relaxed);
}
// Approximate: the two counters are loaded non-atomically with
// relaxed ordering, so the result may momentarily read zero (or
// a lower value) while tasks complete between the two loads.
// Suitable for monitoring and heuristics, not for synchronization.
inline
std::uint64_t
ThreadPool::tasks_pending() const