rust/tests/ui/threads-sendsync/task-comm-15.rs
许杰友 Jieyou Xu (Joe) 95ff642797 tests: remove //@ pretty-expanded usages
Done with

```bash
sd '//@ pretty-expanded.*\n' '' tests/ui/**/*.rs
```

and

```
sd '//@pretty-expanded.*\n' '' tests/ui/**/*.rs
```
2024-11-26 02:50:48 +08:00

25 lines
645 B
Rust

//@ run-pass
#![allow(unused_must_use)]
//@ needs-threads
use std::sync::mpsc::{channel, Sender};
use std::thread;
fn start(tx: &Sender<isize>, i0: isize) {
let mut i = i0;
while i > 0 {
tx.send(0).unwrap();
i = i - 1;
}
}
pub fn main() {
// Spawn a thread that sends us back messages. The parent thread
// is likely to terminate before the child completes, so from
// the child's point of view the receiver may die. We should
// drop messages on the floor in this case, and not crash!
let (tx, rx) = channel();
let t = thread::spawn(move || start(&tx, 10));
rx.recv();
t.join();
}