]> git.lizzy.rs Git - rust.git/blob - tests/ui/threads-sendsync/issue-8827.rs
Auto merge of #106853 - TimNN:undo-remap, r=oli-obk
[rust.git] / tests / ui / threads-sendsync / issue-8827.rs
1 // run-pass
2 // ignore-emscripten no threads support
3
4 use std::thread;
5 use std::sync::mpsc::{channel, Receiver};
6
7 fn periodical(n: isize) -> Receiver<bool> {
8     let (chan, port) = channel();
9     thread::spawn(move|| {
10         loop {
11             for _ in 1..n {
12                 match chan.send(false) {
13                     Ok(()) => {}
14                     Err(..) => break,
15                 }
16             }
17             match chan.send(true) {
18                 Ok(()) => {}
19                 Err(..) => break
20             }
21         }
22     });
23     return port;
24 }
25
26 fn integers() -> Receiver<isize> {
27     let (chan, port) = channel();
28     thread::spawn(move|| {
29         let mut i = 1;
30         loop {
31             match chan.send(i) {
32                 Ok(()) => {}
33                 Err(..) => break,
34             }
35             i = i + 1;
36         }
37     });
38     return port;
39 }
40
41 fn main() {
42     let ints = integers();
43     let threes = periodical(3);
44     let fives = periodical(5);
45     for _ in 1..100 {
46         match (ints.recv().unwrap(), threes.recv().unwrap(), fives.recv().unwrap()) {
47             (_, true, true) => println!("FizzBuzz"),
48             (_, true, false) => println!("Fizz"),
49             (_, false, true) => println!("Buzz"),
50             (i, false, false) => println!("{}", i)
51         }
52     }
53 }