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 ;
@@ -1432,7 +1433,10 @@ impl Inner {
14321433///
14331434/// [`thread::current`]: current::current
14341435pub struct Thread {
1435- inner : Pin < Arc < Inner > > ,
1436+ // We use the System allocator such that creating or dropping this handle
1437+ // does not interfere with a potential Global allocator using thread-local
1438+ // storage.
1439+ inner : Pin < Arc < Inner , System > > ,
14361440}
14371441
14381442impl Thread {
@@ -1445,7 +1449,7 @@ impl Thread {
14451449 // SAFETY: We pin the Arc immediately after creation, so its address never
14461450 // changes.
14471451 let inner = unsafe {
1448- let mut arc = Arc :: < Inner > :: new_uninit ( ) ;
1452+ let mut arc = Arc :: < Inner , _ > :: new_uninit_in ( System ) ;
14491453 let ptr = Arc :: get_mut_unchecked ( & mut arc) . as_mut_ptr ( ) ;
14501454 ( & raw mut ( * ptr) . name ) . write ( name) ;
14511455 ( & raw mut ( * ptr) . id ) . write ( id) ;
@@ -1602,7 +1606,7 @@ impl Thread {
16021606 pub fn into_raw ( self ) -> * const ( ) {
16031607 // Safety: We only expose an opaque pointer, which maintains the `Pin` invariant.
16041608 let inner = unsafe { Pin :: into_inner_unchecked ( self . inner ) } ;
1605- Arc :: into_raw ( inner) as * const ( )
1609+ Arc :: into_raw_with_allocator ( inner) . 0 as * const ( )
16061610 }
16071611
16081612 /// Constructs a `Thread` from a raw pointer.
@@ -1624,7 +1628,9 @@ impl Thread {
16241628 #[ unstable( feature = "thread_raw" , issue = "97523" ) ]
16251629 pub unsafe fn from_raw ( ptr : * const ( ) ) -> Thread {
16261630 // Safety: Upheld by caller.
1627- unsafe { Thread { inner : Pin :: new_unchecked ( Arc :: from_raw ( ptr as * const Inner ) ) } }
1631+ unsafe {
1632+ Thread { inner : Pin :: new_unchecked ( Arc :: from_raw_in ( ptr as * const Inner , System ) ) }
1633+ }
16281634 }
16291635
16301636 fn cname ( & self ) -> Option < & CStr > {
0 commit comments