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 ;
@@ -1463,7 +1464,10 @@ impl Inner {
14631464///
14641465/// [`thread::current`]: current::current
14651466pub struct Thread {
1466- inner : Pin < Arc < Inner > > ,
1467+ // We use the System allocator such that creating or dropping this handle
1468+ // does not interfere with a potential Global allocator using thread-local
1469+ // storage.
1470+ inner : Pin < Arc < Inner , System > > ,
14671471}
14681472
14691473impl Thread {
@@ -1476,7 +1480,7 @@ impl Thread {
14761480 // SAFETY: We pin the Arc immediately after creation, so its address never
14771481 // changes.
14781482 let inner = unsafe {
1479- let mut arc = Arc :: < Inner > :: new_uninit ( ) ;
1483+ let mut arc = Arc :: < Inner , _ > :: new_uninit_in ( System ) ;
14801484 let ptr = Arc :: get_mut_unchecked ( & mut arc) . as_mut_ptr ( ) ;
14811485 ( & raw mut ( * ptr) . name ) . write ( name) ;
14821486 ( & raw mut ( * ptr) . id ) . write ( id) ;
@@ -1647,7 +1651,7 @@ impl Thread {
16471651 pub fn into_raw ( self ) -> * const ( ) {
16481652 // Safety: We only expose an opaque pointer, which maintains the `Pin` invariant.
16491653 let inner = unsafe { Pin :: into_inner_unchecked ( self . inner ) } ;
1650- Arc :: into_raw ( inner) as * const ( )
1654+ Arc :: into_raw_with_allocator ( inner) . 0 as * const ( )
16511655 }
16521656
16531657 /// Constructs a `Thread` from a raw pointer.
@@ -1669,7 +1673,9 @@ impl Thread {
16691673 #[ unstable( feature = "thread_raw" , issue = "97523" ) ]
16701674 pub unsafe fn from_raw ( ptr : * const ( ) ) -> Thread {
16711675 // Safety: Upheld by caller.
1672- unsafe { Thread { inner : Pin :: new_unchecked ( Arc :: from_raw ( ptr as * const Inner ) ) } }
1676+ unsafe {
1677+ Thread { inner : Pin :: new_unchecked ( Arc :: from_raw_in ( ptr as * const Inner , System ) ) }
1678+ }
16731679 }
16741680
16751681 fn cname ( & self ) -> Option < & CStr > {
0 commit comments