162
162
163
163
use prelude:: v1:: * ;
164
164
165
- use alloc:: boxed:: FnBox ;
166
165
use any:: Any ;
167
166
use cell:: UnsafeCell ;
168
167
use fmt;
@@ -249,16 +248,6 @@ impl Builder {
249
248
pub fn spawn < F , T > ( self , f : F ) -> io:: Result < JoinHandle < T > > where
250
249
F : FnOnce ( ) -> T , F : Send + ' static , T : Send + ' static
251
250
{
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 > > {
262
251
let Builder { name, stack_size } = self ;
263
252
264
253
let stack_size = stack_size. unwrap_or ( util:: min_stack ( ) ) ;
@@ -274,22 +263,26 @@ impl Builder {
274
263
if let Some ( name) = their_thread. name ( ) {
275
264
imp:: Thread :: set_name ( name) ;
276
265
}
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
+ }
286
277
} ;
287
278
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
+ } ,
290
283
thread : my_thread,
291
284
packet : Packet ( my_packet) ,
292
- } )
285
+ } ) )
293
286
}
294
287
}
295
288
0 commit comments