/src/test/run-pass/preempt.rs

http://github.com/jruderman/rust · Rust · 22 lines · 18 code · 2 blank · 2 comment · 1 complexity · b7efca8e35cdd2b4124c9374fd95e208 MD5 · raw file

  1. // xfail-test
  2. // This checks that preemption works.
  3. fn starve_main(alive: chan<int>) {
  4. debug!{"signalling main"};
  5. alive <| 1;
  6. debug!{"starving main"};
  7. let i: int = 0;
  8. loop { i += 1; }
  9. }
  10. fn main() {
  11. let alive: port<int> = port();
  12. debug!{"main started"};
  13. let s: task = spawn starve_main(chan(alive));
  14. let i: int;
  15. debug!{"main waiting for alive signal"};
  16. alive |> i;
  17. debug!{"main got alive signal"};
  18. while i < 50 { debug!{"main iterated"}; i += 1; }
  19. debug!{"main completed"};
  20. }