From d53ad428389809867a9ea2f1d9d451cdae29a154 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Fri, 30 Oct 2026 17:58:03 -0400 Subject: [PATCH] Read `size()` in the critical section. --- Concurrency/AsyncTaskQueue.hpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Concurrency/AsyncTaskQueue.hpp b/Concurrency/AsyncTaskQueue.hpp index dbd24804f..7591e3820 100644 --- a/Concurrency/AsyncTaskQueue.hpp +++ b/Concurrency/AsyncTaskQueue.hpp @@ -94,15 +94,20 @@ public: template requires std::invocable void enqueue(FuncT &&action) { + size_t size; { const std::lock_guard guard(condition_mutex_); actions_.emplace_back(std::forward(action)); + + if constexpr (!perform_automatically) { + size = actions_.size(); + } } if constexpr (perform_automatically) { condition_.notify_one(); } else { - if(actions_.size() >= MaximumEnqueueActions) { + if(size >= MaximumEnqueueActions) { condition_.notify_one(); } }