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