Skip to content

Commit

Permalink
Fix potential deadlock on full work queue
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisspyB committed Jan 6, 2025
1 parent 6c2e44f commit a777486
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/gribjump/Task.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,12 @@ void TaskGroup::cancelTasks() {
}

void TaskGroup::enqueueTask(Task* task) {
std::lock_guard<std::mutex> lock(m_);
tasks_.push_back(std::unique_ptr<Task>(task)); // TaskGroup takes ownership of its tasks
WorkQueue::instance().push(task);
{
std::lock_guard<std::mutex> lock(m_);
tasks_.push_back(std::unique_ptr<Task>(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;
}
Expand Down

0 comments on commit a777486

Please sign in to comment.