From ebebe6f837b3499efb5cf1eb95e7eeffbc5e477a Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Wed, 6 Apr 2022 13:50:45 +0200 Subject: Make current_thread_unique_ptr work during thread destruction. Otherwise we can't use println!() within atexit handlers etc. --- library/std/src/sys_common/thread_info.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'library/std/src') diff --git a/library/std/src/sys_common/thread_info.rs b/library/std/src/sys_common/thread_info.rs index cd570dca0ff..b8f2e658214 100644 --- a/library/std/src/sys_common/thread_info.rs +++ b/library/std/src/sys_common/thread_info.rs @@ -34,7 +34,9 @@ impl ThreadInfo { /// /// This can be used as a non-null usize-sized ID. pub fn current_thread_unique_ptr() -> usize { - THREAD_INFO.with(|info| <*const _>::addr(info)) + // Use a non-drop type to make sure it's still available during thread destruction. + thread_local! { static X: u8 = 0 } + X.with(|x| <*const _>::addr(x)) } pub fn current_thread() -> Option { -- cgit 1.4.1-3-g733a5