rust/src/test/run-pass/unique-send-2.rs

24 lines
442 B
Rust
Raw Normal View History

use std;
2012-08-15 16:10:46 -05:00
fn child(c: comm::Chan<~uint>, i: uint) {
comm::send(c, ~i);
}
fn main() {
2012-08-27 16:22:25 -05:00
let p = comm::Port();
let ch = comm::Chan(p);
let n = 100u;
let mut expected = 0u;
2012-06-30 18:19:07 -05:00
for uint::range(0u, n) |i| {
task::spawn(|| child(ch, i) );
expected += i;
}
let mut actual = 0u;
2012-06-30 18:19:07 -05:00
for uint::range(0u, n) |_i| {
let j = comm::recv(p);
actual += *j;
}
assert expected == actual;
}