PageRenderTime 16ms CodeModel.GetById 9ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/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
 4fn starve_main(alive: chan<int>) {
 5    debug!{"signalling main"};
 6    alive <| 1;
 7    debug!{"starving main"};
 8    let i: int = 0;
 9    loop { i += 1; }
10}
11
12fn main() {
13    let alive: port<int> = port();
14    debug!{"main started"};
15    let s: task = spawn starve_main(chan(alive));
16    let i: int;
17    debug!{"main waiting for alive signal"};
18    alive |> i;
19    debug!{"main got alive signal"};
20    while i < 50 { debug!{"main iterated"}; i += 1; }
21    debug!{"main completed"};
22}