Skip to content

Commit b0522e6

Browse files
authored
Merge pull request #2393 from borglab/fan/fix_deadlock
Fix a deadlock under Windows
2 parents 2cf30d6 + d6ea20c commit b0522e6

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

gtsam/base/Scheduler.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ class Scheduler {
122122

123123
// Notify waiters only when work transitions to "done".
124124
if (activeTasks_.fetch_sub(1, std::memory_order_release) == 1) {
125+
std::lock_guard<std::mutex> lock(waitMutex_);
125126
condition_.notify_all();
126127
}
127128
}
@@ -183,7 +184,10 @@ class Scheduler {
183184

184185
queuedTasks_.fetch_add(1, std::memory_order_release);
185186
activeTasks_.fetch_add(1, std::memory_order_release);
186-
condition_.notify_one();
187+
{
188+
std::lock_guard<std::mutex> lock(waitMutex_);
189+
condition_.notify_one();
190+
}
187191
return true;
188192
}
189193

@@ -201,6 +205,7 @@ class Scheduler {
201205
} catch (...) { /* ignore */
202206
}
203207
if (activeTasks_.fetch_sub(1, std::memory_order_release) == 1) {
208+
std::lock_guard<std::mutex> lock(waitMutex_);
204209
condition_.notify_all();
205210
}
206211
}

0 commit comments

Comments
 (0)