Merge pull request #1931 from TomHarte/CriticalSize

Read `size()` in the critical section.
This commit is contained in:
Thomas Harte authored and GitHub committed 2026-10-30 18:17:10 -04:00
commit 5eae9b6101
1 file changed
+6 -1
+6 -1
View File
@@ -94,15 +94,20 @@ public:
template <typename FuncT>
requires std::invocable<FuncT>
void enqueue(FuncT &&action) {
size_t size;
{
const std::lock_guard guard(condition_mutex_);
actions_.emplace_back(std::forward<FuncT>(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();
}
}