]> git.proxmox.com Git - rustc.git/blame - src/test/run-pass/unique-send-2.rs
Imported Upstream version 1.0.0~beta.3
[rustc.git] / src / test / run-pass / unique-send-2.rs
CommitLineData
223e47cc
LB
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
c34b1796 11
1a4d82fc
JJ
12#![allow(unknown_features)]
13#![feature(box_syntax)]
223e47cc 14
1a4d82fc 15use std::sync::mpsc::{channel, Sender};
85aaf69f 16use std::thread;
1a4d82fc 17
c34b1796 18fn child(tx: &Sender<Box<usize>>, i: usize) {
1a4d82fc 19 tx.send(box i).unwrap();
223e47cc
LB
20}
21
22pub fn main() {
1a4d82fc 23 let (tx, rx) = channel();
c34b1796
AL
24 let n = 100;
25 let mut expected = 0;
9346a6ac 26 let ts = (0..n).map(|i| {
223e47cc 27 expected += i;
1a4d82fc 28 let tx = tx.clone();
9346a6ac 29 thread::spawn(move|| {
1a4d82fc
JJ
30 child(&tx, i)
31 })
32 }).collect::<Vec<_>>();
223e47cc 33
c34b1796
AL
34 let mut actual = 0;
35 for _ in 0..n {
1a4d82fc 36 let j = rx.recv().unwrap();
223e47cc
LB
37 actual += *j;
38 }
39
970d7e83 40 assert_eq!(expected, actual);
9346a6ac
AL
41
42 for t in ts { t.join(); }
223e47cc 43}