mirror of
https://github.com/erg-lang/erg.git
synced 2025-07-19 11:05:44 +00:00
chore: add safe_yield
This commit is contained in:
parent
82792aca80
commit
bcd4e4deb7
2 changed files with 8 additions and 2 deletions
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue