poll tidy threads for completion before waiting

This commit is contained in:
The 8472 2022-11-22 00:30:05 +01:00
parent f7bfc48793
commit 5620afc4e0

View File

@ -35,15 +35,26 @@ fn main() {
let bad = std::sync::Arc::new(AtomicBool::new(false));
let drain_handles = |handles: &mut VecDeque<ScopedJoinHandle<'_, ()>>| {
// poll all threads for completion before awaiting the oldest one
for i in (0..handles.len()).rev() {
if handles[i].is_finished() {
handles.swap_remove_back(i).unwrap().join().unwrap();
}
}
while handles.len() >= concurrency.get() {
handles.pop_front().unwrap().join().unwrap();
}
};
scope(|s| {
let mut handles: VecDeque<ScopedJoinHandle<'_, ()>> =
VecDeque::with_capacity(concurrency.get());
macro_rules! check {
($p:ident $(, $args:expr)* ) => {
while handles.len() >= concurrency.get() {
handles.pop_front().unwrap().join().unwrap();
}
drain_handles(&mut handles);
let handle = s.spawn(|| {
let mut flag = false;
@ -97,9 +108,8 @@ macro_rules! check {
check!(alphabetical, &library_path);
let collected = {
while handles.len() >= concurrency.get() {
handles.pop_front().unwrap().join().unwrap();
}
drain_handles(&mut handles);
let mut flag = false;
let r = features::check(&src_path, &compiler_path, &library_path, &mut flag, verbose);
if flag {