aboutsummaryrefslogtreecommitdiff
path: root/libbuild2
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2024-05-09 11:56:11 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2024-05-09 11:56:11 +0200
commitc54e434be71e3cb8e71436cd7397bc4ab9957a7f (patch)
treec9d4bc755011e1b5d05f7036d9197037ea63ac23 /libbuild2
parent2f191a6c6cf1c7802c31fc73e01c5bac17a7f4f1 (diff)
Try to improve deadlock detection accuracy (GH issue 319)
Diffstat (limited to 'libbuild2')
-rw-r--r--libbuild2/scheduler.cxx12
1 files changed, 11 insertions, 1 deletions
diff --git a/libbuild2/scheduler.cxx b/libbuild2/scheduler.cxx
index e3fbcc1..69673e6 100644
--- a/libbuild2/scheduler.cxx
+++ b/libbuild2/scheduler.cxx
@@ -97,6 +97,10 @@ namespace build2
{
// Note: assume non-serial execution.
+ // Note: increment progress before/after every wait.
+ //
+ progress_.fetch_add (1, memory_order_relaxed);
+
lock l (move (rl)); // Make sure unlocked on exception.
active_--;
@@ -135,6 +139,10 @@ namespace build2
{
// Note: assume non-serial execution.
+ // Note: increment progress before/after every wait.
+ //
+ progress_.fetch_add (1, memory_order_relaxed);
+
lock l (mutex_);
if (collision)
@@ -1053,7 +1061,9 @@ namespace build2
// Re-check active/external counts for good measure (in case we were
// spinning too fast).
//
- if (np == op && s.active_ == 0 && s.external_ == 0 && !s.shutdown_)
+ if (np == op &&
+ s.active_ == 0 && s.external_ == 0 && !s.shutdown_ &&
+ s.progress_.load (memory_order_consume) == op)
{
// Shutting things down cleanly is tricky: we could have handled it
// in the scheduler (e.g., by setting a flag and then waking