Skip to content

Commit 78bcd12

Browse files
committed
make sure we only terminate main thread once TLS is initialized
1 parent 66aa3d0 commit 78bcd12

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

tests/run-pass/threadleak_ignored.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,20 @@ thread_local! {
1818

1919
fn main() {
2020
X.with(|x| *x.borrow_mut() = Some(LoudDrop(0)));
21+
22+
// Set up a channel so that we can learn when the other thread initialized `X`
23+
// (so that we are sure there is something to drop).
24+
let (send, recv) = std::sync::mpsc::channel::<()>();
2125

22-
let _detached = std::thread::spawn(|| {
26+
let _detached = std::thread::spawn(move || {
2327
X.with(|x| *x.borrow_mut() = Some(LoudDrop(1)));
28+
send.send(()).unwrap();
29+
std::thread::yield_now();
2430
loop {}
2531
});
32+
33+
std::thread::yield_now();
34+
35+
// Wait until child thread has initialized its `X`.
36+
let () = recv.recv().unwrap();
2637
}

0 commit comments

Comments
 (0)