Skip to content

Commit 129f1e6

Browse files
andrews05shssoichiro
authored andcommitted
Try to fix deadlock in parallel mode
1 parent 798fdfe commit 129f1e6

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/evaluate.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,10 @@ impl Evaluator {
8585
#[cfg(feature = "parallel")]
8686
pub fn get_best_candidate(self) -> Option<Candidate> {
8787
let (eval_send, eval_recv) = self.eval_channel;
88-
drop(eval_send); // disconnect the sender, breaking the loop in the thread
88+
// Disconnect the sender, breaking the loop in the thread
89+
drop(eval_send);
90+
// Yield to ensure evaluations are finished - this can prevent deadlocks when run within an existing thread pool
91+
while let Some(rayon::Yield::Executed) = rayon::yield_local() {}
8992
eval_recv.into_iter().min_by_key(Candidate::cmp_key)
9093
}
9194

0 commit comments

Comments
 (0)