rust/src/test/run-pass/task-comm-14.rs

34 lines
666 B
Rust
Raw Normal View History

// xfail-fast
#[legacy_modes];
2011-09-20 13:47:22 -05:00
fn main() {
let po = pipes::PortSet();
2011-07-27 07:48:34 -05:00
// Spawn 10 tasks each sending us back one int.
let mut i = 10;
2011-07-27 07:48:34 -05:00
while (i > 0) {
log(debug, i);
2012-07-25 16:05:06 -05:00
let (ch, p) = pipes::stream();
2012-09-19 00:45:24 -05:00
po.add(move p);
task::spawn(|move ch, copy i| child(i, ch) );
2011-07-27 07:48:34 -05:00
i = i - 1;
}
// Spawned tasks are likely killed before they get a chance to send
// anything back, so we deadlock here.
i = 10;
while (i > 0) {
log(debug, i);
2012-07-25 16:05:06 -05:00
po.recv();
2011-07-27 07:48:34 -05:00
i = i - 1;
}
2012-08-22 19:24:52 -05:00
debug!("main thread exiting");
2011-07-27 07:48:34 -05:00
}
2012-08-28 13:11:15 -05:00
fn child(x: int, ch: pipes::Chan<int>) {
log(debug, x);
2012-07-25 16:05:06 -05:00
ch.send(x);
2011-07-27 07:48:34 -05:00
}