1 // Copyright 2012-2014 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.
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.
11 // no-pretty-expanded FIXME #15189
13 use std::thread::Thread;
14 use std::sync::mpsc::{channel, Sender};
16 pub fn main() { println!("===== WITHOUT THREADS ====="); test00(); }
18 fn test00_start(ch: &Sender<int>, message: int, count: int) {
19 println!("Starting test00_start");
22 println!("Sending Message");
23 ch.send(message + 0).unwrap();
26 println!("Ending test00_start");
30 let number_of_tasks: int = 16;
31 let number_of_messages: int = 4;
33 println!("Creating tasks");
35 let (tx, rx) = channel();
39 // Create and spawn tasks...
40 let mut results = Vec::new();
41 while i < number_of_tasks {
43 results.push(Thread::scoped({
46 test00_start(&tx, i, number_of_messages)
52 // Read from spawned tasks...
54 for _r in results.iter() {
56 while i < number_of_messages {
57 let value = rx.recv().unwrap();
63 // Join spawned tasks...
64 for r in results.into_iter() { r.join(); }
66 println!("Completed: Final number is: ");
68 // assert (sum == (((number_of_tasks * (number_of_tasks - 1)) / 2) *
69 // number_of_messages));