Skip to content

Commit

Permalink
21149: Improves task lock resilience (#213)
Browse files Browse the repository at this point in the history
  • Loading branch information
howsohazard authored Aug 6, 2024
1 parent ebf48b2 commit 9c00bf1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/Amalgam/ThreadPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,12 @@ class ThreadPool
}
}

//marks one task as completed, but can be called from the thread setting up the tasks
inline void MarkTaskCompletedBeforeWaitForTasks()
{
numTasksCompleted.fetch_add(1);
}

protected:
std::atomic<size_t> numTasks;
std::atomic<size_t> numTasksCompleted;
Expand Down
13 changes: 10 additions & 3 deletions src/Amalgam/evaluablenode/EvaluableNodeManagement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,8 @@ void EvaluableNodeManager::MarkAllReferencedNodesInUse(size_t estimated_nodes_in
//heuristic to ensure there's enough to do to warrant the overhead of using multiple threads
if(Concurrency::GetMaxNumThreads() > 1 && reference_count > 0 && (estimated_nodes_in_use / (reference_count + 1)) >= 1000)
{
ThreadPool::CountableTaskSet task_set;
//allocate all the tasks assuming they will happen, but mark when they can be skipped
ThreadPool::CountableTaskSet task_set(1 + nr.nodesReferenced.size());

//start processing root node first, as there's a good chance it will be the largest
if(root_node != nullptr && !root_node->GetKnownToBeInUseAtomic())
Expand All @@ -855,7 +856,10 @@ void EvaluableNodeManager::MarkAllReferencedNodesInUse(size_t estimated_nodes_in
task_set.MarkTaskCompleted();
}
);
task_set.AddTask();
}
else //autocompleted
{
task_set.MarkTaskCompletedBeforeWaitForTasks();
}

for(auto &[enr, _] : nr.nodesReferenced)
Expand All @@ -874,7 +878,10 @@ void EvaluableNodeManager::MarkAllReferencedNodesInUse(size_t estimated_nodes_in
task_set.MarkTaskCompleted();
}
);
task_set.AddTask();
}
else //autocompleted
{
task_set.MarkTaskCompletedBeforeWaitForTasks();
}
}

Expand Down

0 comments on commit 9c00bf1

Please sign in to comment.