158158#[ cfg( all( test, not( any( target_os = "emscripten" , target_os = "wasi" ) ) ) ) ]
159159mod tests;
160160
161+ use crate :: alloc:: System ;
161162use crate :: any:: Any ;
162163use crate :: cell:: UnsafeCell ;
163164use crate :: ffi:: CStr ;
@@ -1439,7 +1440,10 @@ impl Inner {
14391440///
14401441/// [`thread::current`]: current::current
14411442pub struct Thread {
1442- inner : Pin < Arc < Inner > > ,
1443+ // We use the System allocator such that creating or dropping this handle
1444+ // does not interfere with a potential Global allocator using thread-local
1445+ // storage.
1446+ inner : Pin < Arc < Inner , System > > ,
14431447}
14441448
14451449impl Thread {
@@ -1452,7 +1456,7 @@ impl Thread {
14521456 // SAFETY: We pin the Arc immediately after creation, so its address never
14531457 // changes.
14541458 let inner = unsafe {
1455- let mut arc = Arc :: < Inner > :: new_uninit ( ) ;
1459+ let mut arc = Arc :: < Inner , _ > :: new_uninit_in ( System ) ;
14561460 let ptr = Arc :: get_mut_unchecked ( & mut arc) . as_mut_ptr ( ) ;
14571461 ( & raw mut ( * ptr) . name ) . write ( name) ;
14581462 ( & raw mut ( * ptr) . id ) . write ( id) ;
@@ -1610,7 +1614,7 @@ impl Thread {
16101614 pub fn into_raw ( self ) -> * const ( ) {
16111615 // Safety: We only expose an opaque pointer, which maintains the `Pin` invariant.
16121616 let inner = unsafe { Pin :: into_inner_unchecked ( self . inner ) } ;
1613- Arc :: into_raw ( inner) as * const ( )
1617+ Arc :: into_raw_with_allocator ( inner) . 0 as * const ( )
16141618 }
16151619
16161620 /// Constructs a `Thread` from a raw pointer.
@@ -1632,7 +1636,9 @@ impl Thread {
16321636 #[ unstable( feature = "thread_raw" , issue = "97523" ) ]
16331637 pub unsafe fn from_raw ( ptr : * const ( ) ) -> Thread {
16341638 // Safety: Upheld by caller.
1635- unsafe { Thread { inner : Pin :: new_unchecked ( Arc :: from_raw ( ptr as * const Inner ) ) } }
1639+ unsafe {
1640+ Thread { inner : Pin :: new_unchecked ( Arc :: from_raw_in ( ptr as * const Inner , System ) ) }
1641+ }
16361642 }
16371643
16381644 fn cname ( & self ) -> Option < & CStr > {
0 commit comments