aboutsummaryrefslogtreecommitdiff
path: root/vendor/flume/examples/perf.rs
blob: 054dcbd78523b9062c63c05c07dc69068f3d9220 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
fn main() {
    let thread_num = 32;
    let msg_num = 16;

    let (mut main_tx, main_rx) = flume::bounded::<()>(1);

    for _ in 0..thread_num {
        let (mut tx, rx) = flume::bounded(1);
        std::mem::swap(&mut tx, &mut main_tx);

        std::thread::spawn(move || {
            for msg in rx.iter() {
                tx.send(msg).unwrap();
            }
        });
    }

    for _ in 0..1000 {
        let main_tx = main_tx.clone();
        std::thread::spawn(move || {
            for _ in 0..msg_num {
                main_tx.send(Default::default()).unwrap();
            }
        });

        for _ in 0..msg_num {
            main_rx.recv().unwrap();
        }
    }
}