From 8d3123ece1e5d09cbce914e314de68bc1620b7b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20K=C3=A5re=20Alsaker?= Date: Sun, 23 Mar 2025 08:14:34 +0100 Subject: [PATCH] Fix a race with deadlock detection --- rayon-core/src/sleep/mod.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/rayon-core/src/sleep/mod.rs b/rayon-core/src/sleep/mod.rs index 96e1a68be..48c92802e 100644 --- a/rayon-core/src/sleep/mod.rs +++ b/rayon-core/src/sleep/mod.rs @@ -423,6 +423,10 @@ impl Sleep { let mut is_blocked = sleep_state.is_blocked.lock().unwrap(); if *is_blocked { *is_blocked = false; + + // Increment the number of active threads + self.data.lock().unwrap().active_threads += 1; + sleep_state.condvar.notify_one(); // When the thread went to sleep, it will have incremented @@ -436,9 +440,6 @@ impl Sleep { // do. self.counters.sub_sleeping_thread(); - // Increment the number of active threads - self.data.lock().unwrap().active_threads += 1; - self.logger.log(|| ThreadNotify { worker: index }); true