@@ -35,6 +35,8 @@ struct Scheduler {
35
35
/// Set to `true` while a machine is polling the reactor.
36
36
polling : bool ,
37
37
38
+ progress : bool ,
39
+
38
40
/// Available threads.
39
41
threads : Vec < ThreadState > ,
40
42
@@ -83,6 +85,7 @@ impl Runtime {
83
85
machines : Vec :: with_capacity ( * MAXPROCS ) ,
84
86
threads,
85
87
polling : false ,
88
+ progress : false ,
86
89
} ) ,
87
90
}
88
91
}
@@ -127,7 +130,7 @@ impl Runtime {
127
130
128
131
// println!("getting idle thread");
129
132
let sched = self . sched . lock ( ) . unwrap ( ) ;
130
- ' inner: for ( i , thread) in sched. threads . iter ( ) . enumerate ( ) {
133
+ ' inner: for thread in sched. threads . iter ( ) {
131
134
// grab the first parked thread
132
135
if thread
133
136
. parked
@@ -166,7 +169,7 @@ impl Runtime {
166
169
parker. park ( ) ;
167
170
// TODO: shutdown if idle for too long
168
171
}
169
- // println!("{} thread unparked {}", k , i);
172
+ // println!("thread unparked {}", i);
170
173
// when this thread is unparked, retrieve machine
171
174
let m: Arc < Machine > =
172
175
machine_recv. recv ( ) . expect ( "failed to receive machine" ) ;
@@ -189,8 +192,6 @@ impl Runtime {
189
192
. send ( m)
190
193
. expect ( "failed to send machine to thread" ) ;
191
194
192
- // println!("started thread {}", i);
193
-
194
195
sched. threads . push ( ThreadState {
195
196
unparker,
196
197
parked,
@@ -222,11 +223,14 @@ impl Runtime {
222
223
// If no machine has been polling the reactor in a while, that means the runtime is
223
224
// overloaded with work and we need to start another machine.
224
225
if !sched. polling {
225
- if let Some ( p) = sched. processors . pop ( ) {
226
- let m = Arc :: new ( Machine :: new ( p) ) ;
227
- to_start. push ( m. clone ( ) ) ;
228
- sched. machines . push ( m) ;
226
+ if !sched. progress {
227
+ if let Some ( p) = sched. processors . pop ( ) {
228
+ let m = Arc :: new ( Machine :: new ( p) ) ;
229
+ to_start. push ( m. clone ( ) ) ;
230
+ sched. machines . push ( m) ;
231
+ }
229
232
}
233
+ sched. progress = false ;
230
234
}
231
235
232
236
to_start
@@ -420,13 +424,16 @@ impl Machine {
420
424
sched. polling = false ;
421
425
//println!("polling stop");
422
426
sched. machines . push ( m) ;
427
+ sched. progress = true ;
423
428
424
429
runs = 0 ;
425
430
fails = 0 ;
426
431
}
432
+ // println!("thread break");
427
433
428
434
// When shutting down the thread, take the processor out if still available.
429
435
let opt_p = self . processor . lock ( ) . take ( ) ;
436
+ // println!("processor {:?}", opt_p.is_some());
430
437
431
438
// Return the processor to the scheduler and remove the machine.
432
439
if let Some ( p) = opt_p {
@@ -435,6 +442,7 @@ impl Machine {
435
442
sched. processors . push ( p) ;
436
443
sched. machines . retain ( |elem| !ptr:: eq ( & * * elem, self ) ) ;
437
444
}
445
+ // println!("thread run stopped");
438
446
}
439
447
}
440
448
0 commit comments