Make current_thread_unique_ptr work during thread destruction.

Otherwise we can't use println!() within atexit handlers etc.
This commit is contained in:
Mara Bos
2022-04-06 13:50:45 +02:00
parent bd61bec67d
commit ebebe6f837
+3 -1
View File
@@ -34,7 +34,9 @@ fn with<R, F>(f: F) -> Option<R>
///
/// 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> {