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

27 lines
542 B
Rust
Raw Normal View History

2011-07-27 07:48:34 -05:00
// -*- rust -*-
use std;
import task;
import comm;
2011-10-20 22:34:04 -05:00
fn sub(&&args: (comm::chan<int>, int)) {
let (parent, id) = args;
if id == 0 {
comm::send(parent, 0);
} else {
let p = comm::port();
let child = task::spawn((comm::chan(p), id - 1), sub);
let y = comm::recv(p);
comm::send(parent, y + 1);
}
2011-07-27 07:48:34 -05:00
}
fn main() {
let p = comm::port();
let child = task::spawn((comm::chan(p), 200), sub);
let y = comm::recv(p);
log "transmission complete";
log y;
assert (y == 200);
2011-07-27 07:48:34 -05:00
}