]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/issue-13494.rs
a4f88d7c04c6e38093150b7e2627b8b98feb5d76
[rust.git] / src / test / run-pass / issue-13494.rs
1 // Copyright 2013-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.
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 // This test may not always fail, but it can be flaky if the race it used to
12 // expose is still present.
13
14 extern crate green;
15 extern crate rustuv;
16 extern crate native;
17
18 #[start]
19 fn start(argc: int, argv: **u8) -> int {
20     green::start(argc, argv, rustuv::event_loop, main)
21 }
22
23 fn helper(rx: Receiver<Sender<()>>) {
24     for tx in rx.iter() {
25         let _ = tx.send_opt(());
26     }
27 }
28
29 fn test() {
30     let (tx, rx) = channel();
31     spawn(proc() { helper(rx) });
32     let (snd, rcv) = channel();
33     for _ in range(1i, 100000i) {
34         snd.send(1);
35         let (tx2, rx2) = channel();
36         tx.send(tx2);
37         select! {
38             () = rx2.recv() => (),
39             _ = rcv.recv() => ()
40         }
41     }
42 }
43
44 fn main() {
45     let (tx, rx) = channel();
46     spawn(proc() {
47         tx.send(test());
48     });
49     rx.recv();
50
51     let (tx, rx) = channel();
52     native::task::spawn(proc() {
53         tx.send(test());
54     });
55     rx.recv();
56 }