From 8bcbab5dd1c6449c2acd3ea6a94b245c0936722d Mon Sep 17 00:00:00 2001 From: zachs18 <8355914+zachs18@users.noreply.github.com> Date: Mon, 8 Jul 2024 09:19:25 -0500 Subject: [PATCH] Attempt to fix CI --- library/std/src/sys/exit_guard.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/library/std/src/sys/exit_guard.rs b/library/std/src/sys/exit_guard.rs index ad6246cc83180..5a090f506661d 100644 --- a/library/std/src/sys/exit_guard.rs +++ b/library/std/src/sys/exit_guard.rs @@ -1,5 +1,14 @@ cfg_if::cfg_if! { if #[cfg(target_os = "linux")] { + /// pthread_t is a pointer on some platforms, + /// so we wrap it in this to impl Send + Sync. + #[derive(Clone, Copy)] + #[repr(transparent)] + struct PThread(libc::pthread_t); + // Safety: pthread_t is safe to send between threads + unsafe impl Send for PThread {} + // Safety: pthread_t is safe to share between threads + unsafe impl Sync for PThread {} /// Mitigation for /// /// On glibc, `libc::exit` has been observed to not always be thread-safe. @@ -23,7 +32,7 @@ cfg_if::cfg_if! { pub(crate) fn unique_thread_exit() { let this_thread_id = unsafe { libc::pthread_self() }; use crate::sync::{Mutex, PoisonError}; - static EXITING_THREAD_ID: Mutex> = Mutex::new(None); + static EXITING_THREAD_ID: Mutex> = Mutex::new(None); let mut exiting_thread_id = EXITING_THREAD_ID.lock().unwrap_or_else(PoisonError::into_inner); match *exiting_thread_id { @@ -31,9 +40,9 @@ cfg_if::cfg_if! { // This is the first thread to call `unique_thread_exit`, // and this is the first time it is called. // Set EXITING_THREAD_ID to this thread's ID and return. - *exiting_thread_id = Some(this_thread_id); + *exiting_thread_id = Some(PThread(this_thread_id)); }, - Some(exiting_thread_id) if exiting_thread_id == this_thread_id => { + Some(exiting_thread_id) if exiting_thread_id.0 == this_thread_id => { // This is the first thread to call `unique_thread_exit`, // but this is the second time it is called. // Abort the process.