@@ -379,21 +379,20 @@ impl Scheduler {
379
379
return Some ( task)
380
380
}
381
381
None => {
382
- // Our naive stealing, try kinda hard.
383
382
rtdebug ! ( "scheduler trying to steal" ) ;
384
- let len = self . work_queues . len ( ) ;
385
- return self . try_steals ( len/2 ) ;
383
+ return self . try_steals ( ) ;
386
384
}
387
385
}
388
386
}
389
387
390
- // With no backoff try stealing n times from the queues the
391
- // scheduler knows about. This naive implementation can steal from
392
- // our own queue or from other special schedulers.
393
- fn try_steals ( & mut self , n : uint ) -> Option < ~Task > {
394
- for _ in range ( 0 , n) {
395
- let index = self . rng . gen_uint_range ( 0 , self . work_queues . len ( ) ) ;
396
- let work_queues = & mut self . work_queues ;
388
+ // Try stealing from all queues the scheduler knows about. This
389
+ // naive implementation can steal from our own queue or from other
390
+ // special schedulers.
391
+ fn try_steals ( & mut self ) -> Option < ~Task > {
392
+ let work_queues = & mut self . work_queues ;
393
+ let len = work_queues. len ( ) ;
394
+ let start_index = self . rng . gen_uint_range ( 0 , len) ;
395
+ for index in range ( 0 , len) . map ( |i| ( i + start_index) % len) {
397
396
match work_queues[ index] . steal ( ) {
398
397
Some ( task) => {
399
398
rtdebug ! ( "found task by stealing" ) ;
@@ -1213,4 +1212,22 @@ mod test {
1213
1212
}
1214
1213
}
1215
1214
1215
+ #[ test]
1216
+ fn dont_starve_1 ( ) {
1217
+ use rt:: comm:: oneshot;
1218
+
1219
+ do stress_factor ( ) . times {
1220
+ do run_in_mt_newsched_task {
1221
+ let ( port, chan) = oneshot ( ) ;
1222
+
1223
+ // This task should not be able to starve the sender;
1224
+ // The sender should get stolen to another thread.
1225
+ do spawntask {
1226
+ while !port. peek ( ) { }
1227
+ }
1228
+
1229
+ chan. send ( ( ) ) ;
1230
+ }
1231
+ }
1232
+ }
1216
1233
}
0 commit comments