Reducing the scope of a lock

This commit is contained in:
Ian Roddis
2022-01-13 10:49:09 -04:00
parent 3f5d31e036
commit 854ca5be22

View File

@@ -95,9 +95,10 @@ TaskFuture ForkingTaskExecutor::execute(DAGRunID runID,
const Task &task)
{
std::string key = std::to_string(runID) + "_" + taskName;
std::lock_guard<std::mutex> lock(taskControlsGuard_);
std::unique_lock<std::mutex> lock(taskControlsGuard_);
auto [it, ins] = taskControls_.emplace(key, true);
auto &running = it->second;
lock.unlock();
auto &running = it->second;
return tp_.addTask([this, task, taskName, &running, key]() {
auto ret = this->runTask(task, running);
std::lock_guard<std::mutex> lock(this->taskControlsGuard_);