2011-09-23 17:32:31 -05:00
|
|
|
use std;
|
|
|
|
import std::comm;
|
|
|
|
import std::task;
|
|
|
|
import std::uint;
|
|
|
|
|
2011-10-20 22:34:04 -05:00
|
|
|
fn child(args: (comm::chan<~uint>, uint)) {
|
2011-10-13 17:37:07 -05:00
|
|
|
let (c, i) = args;
|
2011-09-23 17:32:31 -05:00
|
|
|
comm::send(c, ~i);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let p = comm::port();
|
|
|
|
let n = 100u;
|
|
|
|
let expected = 0u;
|
2011-10-21 06:14:28 -05:00
|
|
|
uint::range(0u, n) {|i|
|
2011-10-13 23:23:07 -05:00
|
|
|
task::spawn((comm::chan(p), i), child);
|
2011-09-23 17:32:31 -05:00
|
|
|
expected += i;
|
2011-10-21 06:14:28 -05:00
|
|
|
};
|
2011-09-23 17:32:31 -05:00
|
|
|
|
|
|
|
let actual = 0u;
|
2011-10-21 06:14:28 -05:00
|
|
|
uint::range(0u, n) {|_i|
|
2011-09-23 17:32:31 -05:00
|
|
|
let j = comm::recv(p);
|
|
|
|
actual += *j;
|
2011-10-21 06:14:28 -05:00
|
|
|
};
|
2011-09-23 17:32:31 -05:00
|
|
|
|
|
|
|
assert expected == actual;
|
|
|
|
}
|