162162
163163use prelude:: v1:: * ;
164164
165- use alloc:: boxed:: FnBox ;
166165use any:: Any ;
167166use cell:: UnsafeCell ;
168167use fmt;
@@ -249,16 +248,6 @@ impl Builder {
249248 pub fn spawn < F , T > ( self , f : F ) -> io:: Result < JoinHandle < T > > where
250249 F : FnOnce ( ) -> T , F : Send + ' static , T : Send + ' static
251250 {
252- unsafe {
253- self . spawn_inner ( Box :: new ( f) ) . map ( JoinHandle )
254- }
255- }
256-
257- // NB: this function is unsafe as the lifetime parameter of the code to run
258- // in the new thread is not tied into the return value, and the return
259- // value must not outlast that lifetime.
260- unsafe fn spawn_inner < ' a , T : Send > ( self , f : Box < FnBox ( ) -> T + Send + ' a > )
261- -> io:: Result < JoinInner < T > > {
262251 let Builder { name, stack_size } = self ;
263252
264253 let stack_size = stack_size. unwrap_or ( util:: min_stack ( ) ) ;
@@ -274,22 +263,26 @@ impl Builder {
274263 if let Some ( name) = their_thread. name ( ) {
275264 imp:: Thread :: set_name ( name) ;
276265 }
277- thread_info:: set ( imp:: guard:: current ( ) , their_thread) ;
278- let mut output = None ;
279- let try_result = {
280- let ptr = & mut output;
281- unwind:: try ( move || * ptr = Some ( f ( ) ) )
282- } ;
283- * their_packet. get ( ) = Some ( try_result. map ( |( ) | {
284- output. unwrap ( )
285- } ) ) ;
266+ unsafe {
267+ thread_info:: set ( imp:: guard:: current ( ) , their_thread) ;
268+ let mut output = None ;
269+ let try_result = {
270+ let ptr = & mut output;
271+ unwind:: try ( move || * ptr = Some ( f ( ) ) )
272+ } ;
273+ * their_packet. get ( ) = Some ( try_result. map ( |( ) | {
274+ output. unwrap ( )
275+ } ) ) ;
276+ }
286277 } ;
287278
288- Ok ( JoinInner {
289- native : Some ( try!( imp:: Thread :: new ( stack_size, Box :: new ( main) ) ) ) ,
279+ Ok ( JoinHandle ( JoinInner {
280+ native : unsafe {
281+ Some ( try!( imp:: Thread :: new ( stack_size, Box :: new ( main) ) ) )
282+ } ,
290283 thread : my_thread,
291284 packet : Packet ( my_packet) ,
292- } )
285+ } ) )
293286 }
294287}
295288
0 commit comments