]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/unique-send-2.rs
doc: remove incomplete sentence
[rust.git] / src / test / run-pass / unique-send-2.rs
1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 use std::task;
12 use std::sync::mpsc::{channel, Sender};
13
14 fn child(tx: &Sender<Box<uint>>, i: uint) {
15     tx.send(box i).unwrap();
16 }
17
18 pub fn main() {
19     let (tx, rx) = channel();
20     let n = 100u;
21     let mut expected = 0u;
22     for i in range(0u, n) {
23         let tx = tx.clone();
24         task::spawn(move|| {
25             child(&tx, i)
26         });
27         expected += i;
28     }
29
30     let mut actual = 0u;
31     for _ in range(0u, n) {
32         let j = rx.recv().unwrap();
33         actual += *j;
34     }
35
36     assert_eq!(expected, actual);
37 }