@@ -35,15 +35,26 @@ fn main() {
35
35
36
36
let bad = std:: sync:: Arc :: new ( AtomicBool :: new ( false ) ) ;
37
37
38
+ let drain_handles = |handles : & mut VecDeque < ScopedJoinHandle < ' _ , ( ) > > | {
39
+ // poll all threads for completion before awaiting the oldest one
40
+ for i in ( 0 ..handles. len ( ) ) . rev ( ) {
41
+ if handles[ i] . is_finished ( ) {
42
+ handles. swap_remove_back ( i) . unwrap ( ) . join ( ) . unwrap ( ) ;
43
+ }
44
+ }
45
+
46
+ while handles. len ( ) >= concurrency. get ( ) {
47
+ handles. pop_front ( ) . unwrap ( ) . join ( ) . unwrap ( ) ;
48
+ }
49
+ } ;
50
+
38
51
scope ( |s| {
39
52
let mut handles: VecDeque < ScopedJoinHandle < ' _ , ( ) > > =
40
53
VecDeque :: with_capacity ( concurrency. get ( ) ) ;
41
54
42
55
macro_rules! check {
43
56
( $p: ident $( , $args: expr) * ) => {
44
- while handles. len( ) >= concurrency. get( ) {
45
- handles. pop_front( ) . unwrap( ) . join( ) . unwrap( ) ;
46
- }
57
+ drain_handles( & mut handles) ;
47
58
48
59
let handle = s. spawn( || {
49
60
let mut flag = false ;
@@ -97,9 +108,8 @@ fn main() {
97
108
check ! ( alphabetical, & library_path) ;
98
109
99
110
let collected = {
100
- while handles. len ( ) >= concurrency. get ( ) {
101
- handles. pop_front ( ) . unwrap ( ) . join ( ) . unwrap ( ) ;
102
- }
111
+ drain_handles ( & mut handles) ;
112
+
103
113
let mut flag = false ;
104
114
let r = features:: check ( & src_path, & compiler_path, & library_path, & mut flag, verbose) ;
105
115
if flag {
0 commit comments