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