]> git.lizzy.rs Git - rust.git/blob - src/tools/miri/tests/pass/threadleak_ignored.rs
Rollup merge of #101118 - devnexen:fs_getmode_bsd, r=Mark-Simulacrum
[rust.git] / src / tools / miri / tests / pass / threadleak_ignored.rs
1 //@ignore-target-windows: Channels on Windows are not supported yet.
2 // FIXME: disallow preemption to work around https://github.com/rust-lang/rust/issues/55005
3 //@compile-flags: -Zmiri-ignore-leaks -Zmiri-preemption-rate=0
4
5 //! Test that leaking threads works, and that their destructors are not executed.
6
7 use std::cell::RefCell;
8
9 struct LoudDrop(i32);
10 impl Drop for LoudDrop {
11     fn drop(&mut self) {
12         eprintln!("Dropping {}", self.0);
13     }
14 }
15
16 thread_local! {
17     static X: RefCell<Option<LoudDrop>> = RefCell::new(None);
18 }
19
20 fn main() {
21     X.with(|x| *x.borrow_mut() = Some(LoudDrop(0)));
22
23     // Set up a channel so that we can learn when the other thread initialized `X`
24     // (so that we are sure there is something to drop).
25     let (send, recv) = std::sync::mpsc::channel::<()>();
26
27     let _detached = std::thread::spawn(move || {
28         X.with(|x| *x.borrow_mut() = Some(LoudDrop(1)));
29         send.send(()).unwrap();
30         std::thread::yield_now();
31         loop {}
32     });
33
34     std::thread::yield_now();
35
36     // Wait until child thread has initialized its `X`.
37     let () = recv.recv().unwrap();
38 }