2012-12-10 19:32:48 -06:00
|
|
|
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2013-02-02 05:10:12 -06:00
|
|
|
use core::comm::*;
|
2011-09-23 17:32:31 -05:00
|
|
|
|
2013-01-29 01:54:39 -06:00
|
|
|
fn child(c: &SharedChan<~uint>, i: uint) {
|
|
|
|
c.send(~i);
|
2011-09-23 17:32:31 -05:00
|
|
|
}
|
|
|
|
|
2013-02-01 21:43:17 -06:00
|
|
|
pub fn main() {
|
2013-01-29 01:54:39 -06:00
|
|
|
let (p, ch) = stream();
|
2013-04-17 01:45:29 -05:00
|
|
|
let ch = SharedChan::new(ch);
|
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| {
|
2013-01-29 01:54:39 -06:00
|
|
|
let ch = ch.clone();
|
|
|
|
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| {
|
2013-01-29 01:54:39 -06:00
|
|
|
let j = p.recv();
|
2011-09-23 17:32:31 -05:00
|
|
|
actual += *j;
|
2011-10-21 07:12:12 -05:00
|
|
|
}
|
2011-09-23 17:32:31 -05:00
|
|
|
|
2013-03-28 20:39:09 -05:00
|
|
|
assert!(expected == actual);
|
2013-02-14 13:47:00 -06:00
|
|
|
}
|