Skip to content

Commit d5e0eaf

Browse files
committed
Make current_thread_unique_ptr work during thread destruction.
Otherwise we can't use println!() within atexit handlers etc.
1 parent 619163e commit d5e0eaf

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

library/std/src/sys_common/thread_info.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ impl ThreadInfo {
3434
///
3535
/// This can be used as a non-null usize-sized ID.
3636
pub fn current_thread_unique_ptr() -> usize {
37-
THREAD_INFO.with(|info| <*const _>::addr(info))
37+
// Use a non-drop type to make sure it's still available during thread destruction.
38+
thread_local! { static X: u8 = 0 }
39+
X.with(|x| <*const _>::addr(x))
3840
}
3941

4042
pub fn current_thread() -> Option<Thread> {

0 commit comments

Comments
 (0)