make sure we only terminate main thread once TLS is initialized

This commit is contained in:
Ralf Jung 2021-07-27 14:05:37 +02:00
parent 66aa3d0247
commit 78bcd12b17

View file

@ -18,9 +18,20 @@ thread_local! {
fn main() {
X.with(|x| *x.borrow_mut() = Some(LoudDrop(0)));
// Set up a channel so that we can learn when the other thread initialized `X`
// (so that we are sure there is something to drop).
let (send, recv) = std::sync::mpsc::channel::<()>();
let _detached = std::thread::spawn(|| {
let _detached = std::thread::spawn(move || {
X.with(|x| *x.borrow_mut() = Some(LoudDrop(1)));
send.send(()).unwrap();
std::thread::yield_now();
loop {}
});
std::thread::yield_now();
// Wait until child thread has initialized its `X`.
let () = recv.recv().unwrap();
}