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

27 lines
486 B
Rust
Raw Normal View History

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)) {
let (c, i) = args;
comm::send(c, ~i);
}
fn main() {
let p = comm::port();
let n = 100u;
let expected = 0u;
uint::range(0u, n) {|i|
task::spawn((comm::chan(p), i), child);
expected += i;
};
let actual = 0u;
uint::range(0u, n) {|_i|
let j = comm::recv(p);
actual += *j;
};
assert expected == actual;
}