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
|
|
|
|
2012-01-04 23:14:53 -06:00
|
|
|
fn sub(parent: comm::chan<int>, id: int) {
|
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();
|
2012-01-04 23:14:53 -06:00
|
|
|
let ch = comm::chan(p);
|
2012-06-30 18:19:07 -05:00
|
|
|
let child = task::spawn(|| sub(ch, id - 1) );
|
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();
|
2012-01-04 23:14:53 -06:00
|
|
|
let ch = comm::chan(p);
|
2012-06-30 18:19:07 -05:00
|
|
|
let child = task::spawn(|| sub(ch, 200) );
|
2011-08-25 13:20:43 -05:00
|
|
|
let y = comm::recv(p);
|
2012-07-30 18:01:07 -05:00
|
|
|
debug!{"transmission complete"};
|
2011-12-22 19:53:53 -06:00
|
|
|
log(debug, y);
|
2011-08-19 17:16:48 -05:00
|
|
|
assert (y == 200);
|
2011-07-27 07:48:34 -05:00
|
|
|
}
|