From a77748693a0c980527282967a68fc5bcfae390d6 Mon Sep 17 00:00:00 2001 From: Chris Bradley Date: Mon, 6 Jan 2025 15:49:53 +0000 Subject: [PATCH] Fix potential deadlock on full work queue --- src/gribjump/Task.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/gribjump/Task.cc b/src/gribjump/Task.cc index 54bc4fb..49346e5 100644 --- a/src/gribjump/Task.cc +++ b/src/gribjump/Task.cc @@ -114,9 +114,12 @@ void TaskGroup::cancelTasks() { } void TaskGroup::enqueueTask(Task* task) { - std::lock_guard lock(m_); - tasks_.push_back(std::unique_ptr(task)); // TaskGroup takes ownership of its tasks - WorkQueue::instance().push(task); + { + std::lock_guard lock(m_); + tasks_.push_back(std::unique_ptr(task)); // TaskGroup takes ownership of its tasks + } + + WorkQueue::instance().push(task); /// @note Can block, so release the lock first LOG_DEBUG_LIB(LibGribJump) << "Queued task " << tasks_.size() << std::endl; }