2011-07-27 07:48:34 -05:00
|
|
|
// -*- rust -*-
|
|
|
|
|
2011-08-13 17:20:11 -05:00
|
|
|
use std;
|
2011-12-13 18:25:51 -06:00
|
|
|
import task;
|
|
|
|
import comm;
|
2011-08-13 17:20:11 -05:00
|
|
|
|
2011-10-20 22:34:04 -05:00
|
|
|
fn sub(&&args: (comm::chan<int>, int)) {
|
2011-10-13 17:37:07 -05:00
|
|
|
let (parent, id) = args;
|
2011-08-19 17:16:48 -05:00
|
|
|
if id == 0 {
|
|
|
|
comm::send(parent, 0);
|
|
|
|
} else {
|
2011-08-25 13:20:43 -05:00
|
|
|
let p = comm::port();
|
2011-10-13 23:23:07 -05:00
|
|
|
let child = task::spawn((comm::chan(p), id - 1), sub);
|
2011-08-25 13:20:43 -05:00
|
|
|
let y = comm::recv(p);
|
2011-08-19 17:16:48 -05:00
|
|
|
comm::send(parent, y + 1);
|
|
|
|
}
|
2011-07-27 07:48:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2011-08-25 13:20:43 -05:00
|
|
|
let p = comm::port();
|
2011-10-13 23:23:07 -05:00
|
|
|
let child = task::spawn((comm::chan(p), 200), sub);
|
2011-08-25 13:20:43 -05:00
|
|
|
let y = comm::recv(p);
|
2011-08-19 17:16:48 -05:00
|
|
|
log "transmission complete";
|
|
|
|
log y;
|
|
|
|
assert (y == 200);
|
2011-07-27 07:48:34 -05:00
|
|
|
}
|