]> git.proxmox.com Git - rustc.git/blob - tests/ui/box/unit/unique-send-2.rs
Update upstream source from tag 'upstream/1.70.0+dfsg1'
[rustc.git] / tests / ui / box / unit / unique-send-2.rs
1 // run-pass
2 #![allow(unused_must_use)]
3 // ignore-emscripten no threads support
4
5 use std::sync::mpsc::{channel, Sender};
6 use std::thread;
7
8 fn child(tx: &Sender<Box<usize>>, i: usize) {
9 tx.send(Box::new(i)).unwrap();
10 }
11
12 pub fn main() {
13 let (tx, rx) = channel();
14 let n = 100;
15 let mut expected = 0;
16 let ts = (0..n).map(|i| {
17 expected += i;
18 let tx = tx.clone();
19 thread::spawn(move|| {
20 child(&tx, i)
21 })
22 }).collect::<Vec<_>>();
23
24 let mut actual = 0;
25 for _ in 0..n {
26 let j = rx.recv().unwrap();
27 actual += *j;
28 }
29
30 assert_eq!(expected, actual);
31
32 for t in ts { t.join(); }
33 }