@@ -386,6 +386,13 @@ impl Builder {
386
386
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
387
387
pub fn spawn < F , T > ( self , f : F ) -> io:: Result < JoinHandle < T > > where
388
388
F : FnOnce ( ) -> T , F : Send + ' static , T : Send + ' static
389
+ {
390
+ unsafe { self . spawn_unchecked ( f) }
391
+ }
392
+
393
+ /// TODO: Doc
394
+ pub unsafe fn spawn_unchecked < ' a , F , T > ( self , f : F ) -> io:: Result < JoinHandle < T > > where
395
+ F : FnOnce ( ) -> T , F : Send + ' a , T : Send + ' a
389
396
{
390
397
let Builder { name, stack_size } = self ;
391
398
@@ -402,16 +409,15 @@ impl Builder {
402
409
if let Some ( name) = their_thread. cname ( ) {
403
410
imp:: Thread :: set_name ( name) ;
404
411
}
405
- unsafe {
406
- thread_info:: set ( imp:: guard:: current ( ) , their_thread) ;
407
- #[ cfg( feature = "backtrace" ) ]
408
- let try_result = panic:: catch_unwind ( panic:: AssertUnwindSafe ( || {
409
- :: sys_common:: backtrace:: __rust_begin_short_backtrace ( f)
410
- } ) ) ;
411
- #[ cfg( not( feature = "backtrace" ) ) ]
412
- let try_result = panic:: catch_unwind ( panic:: AssertUnwindSafe ( f) ) ;
413
- * their_packet. get ( ) = Some ( try_result) ;
414
- }
412
+
413
+ thread_info:: set ( imp:: guard:: current ( ) , their_thread) ;
414
+ #[ cfg( feature = "backtrace" ) ]
415
+ let try_result = panic:: catch_unwind ( panic:: AssertUnwindSafe ( || {
416
+ :: sys_common:: backtrace:: __rust_begin_short_backtrace ( f)
417
+ } ) ) ;
418
+ #[ cfg( not( feature = "backtrace" ) ) ]
419
+ let try_result = panic:: catch_unwind ( panic:: AssertUnwindSafe ( f) ) ;
420
+ * their_packet. get ( ) = Some ( try_result) ;
415
421
} ;
416
422
417
423
Ok ( JoinHandle ( JoinInner {
@@ -420,7 +426,7 @@ impl Builder {
420
426
} ,
421
427
thread : my_thread,
422
428
packet : Packet ( my_packet) ,
423
- } ) )
429
+ } ) )
424
430
}
425
431
}
426
432
0 commit comments