@@ -159,6 +159,7 @@ use crate::cell::UnsafeCell;
159159use crate :: ffi:: { CStr , CString } ;
160160use crate :: fmt;
161161use crate :: io;
162+ use crate :: marker:: PhantomData ;
162163use crate :: mem;
163164use crate :: num:: NonZeroU64 ;
164165use crate :: num:: NonZeroUsize ;
@@ -462,7 +463,7 @@ impl Builder {
462463 unsafe fn spawn_unchecked_ < ' a , ' scope , F , T > (
463464 self ,
464465 f : F ,
465- scope_data : Option < & ' scope scoped:: ScopeData > ,
466+ scope_data : Option < Arc < scoped:: ScopeData > > ,
466467 ) -> io:: Result < JoinInner < ' scope , T > >
467468 where
468469 F : FnOnce ( ) -> T ,
@@ -479,8 +480,11 @@ impl Builder {
479480 } ) ) ;
480481 let their_thread = my_thread. clone ( ) ;
481482
482- let my_packet: Arc < Packet < ' scope , T > > =
483- Arc :: new ( Packet { scope : scope_data, result : UnsafeCell :: new ( None ) } ) ;
483+ let my_packet: Arc < Packet < ' scope , T > > = Arc :: new ( Packet {
484+ scope : scope_data,
485+ result : UnsafeCell :: new ( None ) ,
486+ _marker : PhantomData ,
487+ } ) ;
484488 let their_packet = my_packet. clone ( ) ;
485489
486490 let output_capture = crate :: io:: set_output_capture ( None ) ;
@@ -507,7 +511,7 @@ impl Builder {
507511 unsafe { * their_packet. result . get ( ) = Some ( try_result) } ;
508512 } ;
509513
510- if let Some ( scope_data) = scope_data {
514+ if let Some ( scope_data) = & my_packet . scope {
511515 scope_data. increment_num_running_threads ( ) ;
512516 }
513517
@@ -1298,8 +1302,9 @@ pub type Result<T> = crate::result::Result<T, Box<dyn Any + Send + 'static>>;
12981302// An Arc to the packet is stored into a `JoinInner` which in turns is placed
12991303// in `JoinHandle`.
13001304struct Packet < ' scope , T > {
1301- scope : Option < & ' scope scoped:: ScopeData > ,
1305+ scope : Option < Arc < scoped:: ScopeData > > ,
13021306 result : UnsafeCell < Option < Result < T > > > ,
1307+ _marker : PhantomData < Option < & ' scope scoped:: ScopeData > > ,
13031308}
13041309
13051310// Due to the usage of `UnsafeCell` we need to manually implement Sync.
@@ -1330,7 +1335,7 @@ impl<'scope, T> Drop for Packet<'scope, T> {
13301335 rtabort ! ( "thread result panicked on drop" ) ;
13311336 }
13321337 // Book-keeping so the scope knows when it's done.
1333- if let Some ( scope) = self . scope {
1338+ if let Some ( scope) = & self . scope {
13341339 // Now that there will be no more user code running on this thread
13351340 // that can use 'scope, mark the thread as 'finished'.
13361341 // It's important we only do this after the `result` has been dropped,
0 commit comments