2011-09-23 17:32:31 -05:00
|
|
|
use std;
|
2011-12-13 18:25:51 -06:00
|
|
|
import comm;
|
|
|
|
import task;
|
|
|
|
import uint;
|
2011-09-23 17:32:31 -05:00
|
|
|
|
2012-01-04 23:14:53 -06:00
|
|
|
fn child(c: comm::chan<~uint>, i: uint) {
|
2011-09-23 17:32:31 -05:00
|
|
|
comm::send(c, ~i);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let p = comm::port();
|
2012-01-04 23:14:53 -06:00
|
|
|
let ch = comm::chan(p);
|
2011-09-23 17:32:31 -05:00
|
|
|
let n = 100u;
|
2012-03-22 10:39:41 -05:00
|
|
|
let mut expected = 0u;
|
2012-05-26 02:32:08 -05:00
|
|
|
for uint::range(0u, n) {|i|
|
2012-06-26 15:55:56 -05:00
|
|
|
task::spawn({|| child(ch, i); });
|
2011-09-23 17:32:31 -05:00
|
|
|
expected += i;
|
2011-10-21 07:12:12 -05:00
|
|
|
}
|
2011-09-23 17:32:31 -05:00
|
|
|
|
2012-03-22 10:39:41 -05:00
|
|
|
let mut actual = 0u;
|
2012-05-26 02:32:08 -05:00
|
|
|
for uint::range(0u, n) {|_i|
|
2011-09-23 17:32:31 -05:00
|
|
|
let j = comm::recv(p);
|
|
|
|
actual += *j;
|
2011-10-21 07:12:12 -05:00
|
|
|
}
|
2011-09-23 17:32:31 -05:00
|
|
|
|
|
|
|
assert expected == actual;
|
|
|
|
}
|