chore: add safe_yield

This commit is contained in:
Shunsuke Shibayama 2023-08-21 22:50:08 +09:00
parent 82792aca80
commit bcd4e4deb7
2 changed files with 8 additions and 2 deletions

View file

@ -50,3 +50,8 @@ where
.spawn(run)
.unwrap()
}
pub fn safe_yield() {
std::thread::yield_now();
std::thread::sleep(std::time::Duration::from_millis(10));
}

View file

@ -5,6 +5,7 @@ use std::thread::{current, JoinHandle, ThreadId};
use erg_common::dict::Dict;
use erg_common::pathutil::NormalizedPathBuf;
use erg_common::shared::Shared;
use erg_common::spawn::safe_yield;
use super::SharedModuleGraph;
@ -155,7 +156,7 @@ impl SharedPromises {
.get(path)
.is_some_and(|p| !p.is_finished())
{
std::thread::yield_now();
safe_yield();
}
return Ok(());
}
@ -167,7 +168,7 @@ impl SharedPromises {
pub fn join(&self, path: &Path) -> std::thread::Result<()> {
while let Some(Promise::Joining) | None = self.promises.borrow().get(path) {
std::thread::yield_now();
safe_yield();
}
let promise = self.promises.borrow_mut().get_mut(path).unwrap().take();
self.join_checked(path, promise)