mirror of
https://github.com/rust-lang/rust.git
synced 2026-06-01 22:18:23 +03:00
make sure we only terminate main thread once TLS is initialized
This commit is contained in:
@@ -18,9 +18,20 @@ fn drop(&mut self) {
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user