From 64d98f8ee037282c35007b64c2649055c56af1db Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:19:03 +0200 Subject: Merging upstream version 1.68.2+dfsg1. Signed-off-by: Daniel Baumann --- tests/ui/unique/unique-send-2.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 tests/ui/unique/unique-send-2.rs (limited to 'tests/ui/unique/unique-send-2.rs') diff --git a/tests/ui/unique/unique-send-2.rs b/tests/ui/unique/unique-send-2.rs new file mode 100644 index 000000000..23ddd2cdc --- /dev/null +++ b/tests/ui/unique/unique-send-2.rs @@ -0,0 +1,33 @@ +// run-pass +#![allow(unused_must_use)] +// ignore-emscripten no threads support + +use std::sync::mpsc::{channel, Sender}; +use std::thread; + +fn child(tx: &Sender>, i: usize) { + tx.send(Box::new(i)).unwrap(); +} + +pub fn main() { + let (tx, rx) = channel(); + let n = 100; + let mut expected = 0; + let ts = (0..n).map(|i| { + expected += i; + let tx = tx.clone(); + thread::spawn(move|| { + child(&tx, i) + }) + }).collect::>(); + + let mut actual = 0; + for _ in 0..n { + let j = rx.recv().unwrap(); + actual += *j; + } + + assert_eq!(expected, actual); + + for t in ts { t.join(); } +} -- cgit v1.2.3