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

42 lines
1.1 KiB
Rust
Raw Normal View History

// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// xfail-test
2010-06-24 04:03:09 +00:00
// This checks that preemption works.
2013-06-22 18:43:15 +00:00
// note: halfway done porting to modern rust
extern mod extra;
use std::comm;
use extra::comm;
fn starve_main(alive: Port<int>) {
info!("signalling main");
2013-06-22 18:43:15 +00:00
alive.recv();
info!("starving main");
2013-06-22 18:43:15 +00:00
let mut i: int = 0;
loop { i += 1; }
2010-06-24 04:03:09 +00:00
}
pub fn main() {
2013-06-22 18:43:15 +00:00
let (port, chan) = stream();
info!("main started");
2013-06-22 18:43:15 +00:00
do spawn {
starve_main(port);
};
2013-06-22 18:43:15 +00:00
let mut i: int = 0;
info!("main waiting for alive signal");
2013-06-22 18:43:15 +00:00
chan.send(i);
info!("main got alive signal");
while i < 50 { info!("main iterated"); i += 1; }
info!("main completed");
}