From 129f1e6f76de1cacd55a4d95f066c94dc0a44dd4 Mon Sep 17 00:00:00 2001 From: Andrew Date: Mon, 19 Jun 2023 22:34:34 +1200 Subject: [PATCH] Try to fix deadlock in parallel mode --- src/evaluate.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/evaluate.rs b/src/evaluate.rs index 0d187198..da84ac13 100644 --- a/src/evaluate.rs +++ b/src/evaluate.rs @@ -85,7 +85,10 @@ impl Evaluator { #[cfg(feature = "parallel")] pub fn get_best_candidate(self) -> Option { let (eval_send, eval_recv) = self.eval_channel; - drop(eval_send); // disconnect the sender, breaking the loop in the thread + // Disconnect the sender, breaking the loop in the thread + drop(eval_send); + // Yield to ensure evaluations are finished - this can prevent deadlocks when run within an existing thread pool + while let Some(rayon::Yield::Executed) = rayon::yield_local() {} eval_recv.into_iter().min_by_key(Candidate::cmp_key) }