@@ -159,6 +159,7 @@ use crate::cell::UnsafeCell;
159
159
use crate :: ffi:: { CStr , CString } ;
160
160
use crate :: fmt;
161
161
use crate :: io;
162
+ use crate :: marker:: PhantomData ;
162
163
use crate :: mem;
163
164
use crate :: num:: NonZeroU64 ;
164
165
use crate :: num:: NonZeroUsize ;
@@ -462,7 +463,7 @@ impl Builder {
462
463
unsafe fn spawn_unchecked_ < ' a , ' scope , F , T > (
463
464
self ,
464
465
f : F ,
465
- scope_data : Option < & ' scope scoped:: ScopeData > ,
466
+ scope_data : Option < Arc < scoped:: ScopeData > > ,
466
467
) -> io:: Result < JoinInner < ' scope , T > >
467
468
where
468
469
F : FnOnce ( ) -> T ,
@@ -479,8 +480,11 @@ impl Builder {
479
480
} ) ) ;
480
481
let their_thread = my_thread. clone ( ) ;
481
482
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
+ } ) ;
484
488
let their_packet = my_packet. clone ( ) ;
485
489
486
490
let output_capture = crate :: io:: set_output_capture ( None ) ;
@@ -507,7 +511,7 @@ impl Builder {
507
511
unsafe { * their_packet. result . get ( ) = Some ( try_result) } ;
508
512
} ;
509
513
510
- if let Some ( scope_data) = scope_data {
514
+ if let Some ( scope_data) = & my_packet . scope {
511
515
scope_data. increment_num_running_threads ( ) ;
512
516
}
513
517
@@ -1298,8 +1302,9 @@ pub type Result<T> = crate::result::Result<T, Box<dyn Any + Send + 'static>>;
1298
1302
// An Arc to the packet is stored into a `JoinInner` which in turns is placed
1299
1303
// in `JoinHandle`.
1300
1304
struct Packet < ' scope , T > {
1301
- scope : Option < & ' scope scoped:: ScopeData > ,
1305
+ scope : Option < Arc < scoped:: ScopeData > > ,
1302
1306
result : UnsafeCell < Option < Result < T > > > ,
1307
+ _marker : PhantomData < Option < & ' scope scoped:: ScopeData > > ,
1303
1308
}
1304
1309
1305
1310
// Due to the usage of `UnsafeCell` we need to manually implement Sync.
@@ -1330,7 +1335,7 @@ impl<'scope, T> Drop for Packet<'scope, T> {
1330
1335
rtabort ! ( "thread result panicked on drop" ) ;
1331
1336
}
1332
1337
// Book-keeping so the scope knows when it's done.
1333
- if let Some ( scope) = self . scope {
1338
+ if let Some ( scope) = & self . scope {
1334
1339
// Now that there will be no more user code running on this thread
1335
1340
// that can use 'scope, mark the thread as 'finished'.
1336
1341
// It's important we only do this after the `result` has been dropped,
0 commit comments