@@ -386,6 +386,13 @@ impl Builder {
386386 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
387387 pub fn spawn < F , T > ( self , f : F ) -> io:: Result < JoinHandle < T > > where
388388 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
389396 {
390397 let Builder { name, stack_size } = self ;
391398
@@ -402,16 +409,15 @@ impl Builder {
402409 if let Some ( name) = their_thread. cname ( ) {
403410 imp:: Thread :: set_name ( name) ;
404411 }
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) ;
415421 } ;
416422
417423 Ok ( JoinHandle ( JoinInner {
@@ -420,7 +426,7 @@ impl Builder {
420426 } ,
421427 thread : my_thread,
422428 packet : Packet ( my_packet) ,
423- } ) )
429+ } ) )
424430 }
425431}
426432
0 commit comments