about summary refs log tree commit diff
path: root/library/std/src
diff options
context:
space:
mode:
authorMara Bos <m-ou.se@m-ou.se>2022-04-06 13:50:45 +0200
committerMara Bos <m-ou.se@m-ou.se>2022-04-12 08:44:38 +0200
commitebebe6f837b3499efb5cf1eb95e7eeffbc5e477a (patch)
tree9d3314c66d2c26c02ec26f1a1ef84556a782add1 /library/std/src
parentbd61bec67d23e11a37a19a3a554753419c734947 (diff)
downloadrust-ebebe6f837b3499efb5cf1eb95e7eeffbc5e477a.tar.gz
rust-ebebe6f837b3499efb5cf1eb95e7eeffbc5e477a.zip
Make current_thread_unique_ptr work during thread destruction.
Otherwise we can't use println!() within atexit handlers etc.
Diffstat (limited to 'library/std/src')
-rw-r--r--library/std/src/sys_common/thread_info.rs4
1 files changed, 3 insertions, 1 deletions
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<Thread> {