Skip to content

Commit dcf5de5

Browse files
committed
Thread/ScheduledEventDispatcher: flush() : Fix deadlock
1 parent 9905ea1 commit dcf5de5

2 files changed

Lines changed: 12 additions & 10 deletions

File tree

modules/Container/NetworkPtr.mpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ export namespace CppUtils::Container
188188

189189
inline auto updateDistance(const WeakPtr& lockedParentWeak = {}, std::size_t lockedParentDistance = std::numeric_limits<std::size_t>::max()) -> void
190190
{
191-
auto oldDistanceFromRoot = m_distanceFromRoot;
191+
const auto oldDistanceFromRoot = m_distanceFromRoot;
192192

193193
m_distanceFromRoot = std::numeric_limits<std::size_t>::max();
194194
for (const auto& parentWeak : m_parents)

modules/Thread/Scheduler.mpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,16 @@ export namespace CppUtils::Thread
111111

112112
inline auto flush() -> void
113113
{
114-
auto tasksToRun = std::vector<std::shared_ptr<Item>>{};
114+
while (true)
115115
{
116-
auto accessor = m_items.access();
117-
auto& [set, map, processingTasks] = accessor.value();
118-
119-
if (not std::empty(set))
116+
auto tasksToRun = std::vector<std::shared_ptr<Item>>{};
120117
{
118+
auto accessor = m_items.access();
119+
auto& [set, map, processingTasks] = accessor.value();
120+
121+
if (std::empty(set))
122+
break;
123+
121124
tasksToRun.assign(std::begin(set), std::end(set));
122125
processingTasks += std::size(set);
123126
map.clear();
@@ -126,11 +129,10 @@ export namespace CppUtils::Thread
126129
m_workCondition.notify_all();
127130
m_finishedCondition.notify_all();
128131
}
132+
dispatchTasks(std::move(tasksToRun));
129133
}
130-
131-
dispatchTasks(std::move(tasksToRun));
132-
133-
waitUntilFinished();
134+
m_workCondition.notify_all();
135+
m_finishedCondition.notify_all();
134136
}
135137

136138
inline auto cancel(std::size_t id) -> void

0 commit comments

Comments
 (0)