rust/src/test/run-pass/preempt.rs
Tim Chevalier 321fd80219 Add an infinite loop construct
Add a loop {} construct for infinite loops, and use it in test
cases. See #1906 for details.
2012-03-09 16:40:58 -08:00

23 lines
533 B
Rust

// xfail-test
// This checks that preemption works.
fn starve_main(alive: chan<int>) {
#debug("signalling main");
alive <| 1;
#debug("starving main");
let i: int = 0;
loop { i += 1; }
}
fn main() {
let alive: port<int> = port();
#debug("main started");
let s: task = spawn starve_main(chan(alive));
let i: int;
#debug("main waiting for alive signal");
alive |> i;
#debug("main got alive signal");
while i < 50 { #debug("main iterated"); i += 1; }
#debug("main completed");
}