]> git.proxmox.com Git - rustc.git/blame - src/test/run-pass/task-comm-9.rs
New upstream version 1.19.0+dfsg1
[rustc.git] / src / test / run-pass / task-comm-9.rs
CommitLineData
1a4d82fc 1// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
223e47cc
LB
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
7453a54e
SL
11// ignore-emscripten no threads support
12
c34b1796
AL
13#![feature(std_misc)]
14
15use std::thread;
1a4d82fc 16use std::sync::mpsc::{channel, Sender};
223e47cc
LB
17
18pub fn main() { test00(); }
19
c34b1796
AL
20fn test00_start(c: &Sender<isize>, number_of_messages: isize) {
21 let mut i: isize = 0;
1a4d82fc 22 while i < number_of_messages { c.send(i + 0).unwrap(); i += 1; }
223e47cc
LB
23}
24
25fn test00() {
c34b1796
AL
26 let r: isize = 0;
27 let mut sum: isize = 0;
1a4d82fc 28 let (tx, rx) = channel();
c34b1796 29 let number_of_messages: isize = 10;
223e47cc 30
9346a6ac 31 let result = thread::spawn(move|| {
1a4d82fc
JJ
32 test00_start(&tx, number_of_messages);
33 });
223e47cc 34
c34b1796 35 let mut i: isize = 0;
223e47cc 36 while i < number_of_messages {
1a4d82fc
JJ
37 sum += rx.recv().unwrap();
38 println!("{}", r);
223e47cc
LB
39 i += 1;
40 }
41
1a4d82fc 42 result.join();
223e47cc 43
970d7e83 44 assert_eq!(sum, number_of_messages * (number_of_messages - 1) / 2);
223e47cc 45}