2011-09-23 17:32:31 -05:00
|
|
|
use std;
|
|
|
|
|
2012-08-15 16:10:46 -05:00
|
|
|
fn child(c: comm::Chan<~uint>, i: uint) {
|
2011-09-23 17:32:31 -05:00
|
|
|
comm::send(c, ~i);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2012-08-27 16:22:25 -05:00
|
|
|
let p = comm::Port();
|
|
|
|
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-06-30 18:19:07 -05:00
|
|
|
for uint::range(0u, n) |i| {
|
|
|
|
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-06-30 18:19:07 -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;
|
|
|
|
}
|