Skip to content

Commit bcd4e4d

Browse files
committed
chore: add safe_yield
1 parent 82792ac commit bcd4e4d

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

crates/erg_common/spawn.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,8 @@ where
5050
.spawn(run)
5151
.unwrap()
5252
}
53+
54+
pub fn safe_yield() {
55+
std::thread::yield_now();
56+
std::thread::sleep(std::time::Duration::from_millis(10));
57+
}

crates/erg_compiler/module/promise.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::thread::{current, JoinHandle, ThreadId};
55
use erg_common::dict::Dict;
66
use erg_common::pathutil::NormalizedPathBuf;
77
use erg_common::shared::Shared;
8+
use erg_common::spawn::safe_yield;
89

910
use super::SharedModuleGraph;
1011

@@ -155,7 +156,7 @@ impl SharedPromises {
155156
.get(path)
156157
.is_some_and(|p| !p.is_finished())
157158
{
158-
std::thread::yield_now();
159+
safe_yield();
159160
}
160161
return Ok(());
161162
}
@@ -167,7 +168,7 @@ impl SharedPromises {
167168

168169
pub fn join(&self, path: &Path) -> std::thread::Result<()> {
169170
while let Some(Promise::Joining) | None = self.promises.borrow().get(path) {
170-
std::thread::yield_now();
171+
safe_yield();
171172
}
172173
let promise = self.promises.borrow_mut().get_mut(path).unwrap().take();
173174
self.join_checked(path, promise)

0 commit comments

Comments
 (0)