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.
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 // Based on threadring.erlang by Jira Isa
15 fn start(n_tasks: int, token: int) {
16 let (tx, mut rx) = channel();
18 // XXX could not get this to work with a range closure
21 let (tx, next_rx) = channel();
25 roundtrip(imm_i, n_tasks, &imm_rx, &tx);
32 roundtrip(1, n_tasks, &imm_rx, &tx);
36 fn roundtrip(id: int, n_tasks: int, p: &Receiver<int>, ch: &Sender<int>) {
44 println!("thread: {} got token: {}", id, token);
55 use std::from_str::FromStr;
57 let args = if os::getenv("RUST_BENCH").is_some() {
58 vec!(~"", ~"2000000", ~"503")
63 let token = if args.len() > 1u {
64 FromStr::from_str(args[1]).unwrap()
69 let n_tasks = if args.len() > 2u {
70 FromStr::from_str(args[2]).unwrap()
75 start(n_tasks, token);