2011-07-27 07:48:34 -05:00
|
|
|
// -*- rust -*-
|
|
|
|
|
2011-08-13 17:20:11 -05:00
|
|
|
use std;
|
|
|
|
import std::task;
|
|
|
|
import std::comm;
|
|
|
|
|
|
|
|
fn sub(parent: comm::_chan[int], id: int) {
|
2011-07-27 07:48:34 -05:00
|
|
|
if (id == 0) {
|
2011-08-13 17:20:11 -05:00
|
|
|
comm::send(parent, 0);
|
2011-07-27 07:48:34 -05:00
|
|
|
} else {
|
2011-08-13 17:20:11 -05:00
|
|
|
let p = comm::mk_port();
|
|
|
|
let child = task::_spawn(bind sub(p.mk_chan(), id-1));
|
|
|
|
let y = p.recv();
|
|
|
|
comm::send(parent, y + 1);
|
2011-07-27 07:48:34 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2011-08-13 17:20:11 -05:00
|
|
|
let p = comm::mk_port();
|
|
|
|
let child = task::_spawn(bind sub(p.mk_chan(), 200));
|
|
|
|
let y = p.recv();
|
2011-07-27 07:48:34 -05:00
|
|
|
log "transmission complete";
|
|
|
|
log y;
|
2011-08-11 00:06:46 -05:00
|
|
|
assert (y == 200);
|
2011-07-27 07:48:34 -05:00
|
|
|
}
|