]> git.proxmox.com Git - rustc.git/blame - 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
CommitLineData
b7449926 1// run-pass
0bf4aa26 2#![allow(unused_must_use)]
7453a54e 3// ignore-emscripten no threads support
c34b1796 4
1a4d82fc 5use std::sync::mpsc::{channel, Sender};
85aaf69f 6use std::thread;
1a4d82fc 7
c34b1796 8fn child(tx: &Sender<Box<usize>>, i: usize) {
c295e0f8 9 tx.send(Box::new(i)).unwrap();
223e47cc
LB
10}
11
12pub fn main() {
1a4d82fc 13 let (tx, rx) = channel();
c34b1796
AL
14 let n = 100;
15 let mut expected = 0;
9346a6ac 16 let ts = (0..n).map(|i| {
223e47cc 17 expected += i;
1a4d82fc 18 let tx = tx.clone();
9346a6ac 19 thread::spawn(move|| {
1a4d82fc
JJ
20 child(&tx, i)
21 })
22 }).collect::<Vec<_>>();
223e47cc 23
c34b1796
AL
24 let mut actual = 0;
25 for _ in 0..n {
1a4d82fc 26 let j = rx.recv().unwrap();
223e47cc
LB
27 actual += *j;
28 }
29
970d7e83 30 assert_eq!(expected, actual);
9346a6ac
AL
31
32 for t in ts { t.join(); }
223e47cc 33}