@@ -257,7 +257,7 @@ impl Builder {
257
257
pub fn spawn < F > ( self , f : F ) -> io:: Result < JoinHandle > where
258
258
F : FnOnce ( ) , F : Send + ' static
259
259
{
260
- self . spawn_inner ( Thunk :: new ( f) ) . map ( |i| JoinHandle ( i) )
260
+ self . spawn_inner ( Box :: new ( f) ) . map ( |i| JoinHandle ( i) )
261
261
}
262
262
263
263
/// Spawn a new child thread that must be joined within a given
@@ -279,7 +279,7 @@ impl Builder {
279
279
pub fn scoped < ' a , T , F > ( self , f : F ) -> io:: Result < JoinGuard < ' a , T > > where
280
280
T : Send + ' a , F : FnOnce ( ) -> T , F : Send + ' a
281
281
{
282
- self . spawn_inner ( Thunk :: new ( f) ) . map ( |inner| {
282
+ self . spawn_inner ( Box :: new ( f) ) . map ( |inner| {
283
283
JoinGuard { inner : inner, _marker : PhantomData }
284
284
} )
285
285
}
@@ -315,7 +315,7 @@ impl Builder {
315
315
thread_info:: set ( imp:: guard:: current ( ) , their_thread) ;
316
316
}
317
317
318
- let mut output = None ;
318
+ let mut output: Option < T > = None ;
319
319
let try_result = {
320
320
let ptr = & mut output;
321
321
@@ -327,7 +327,11 @@ impl Builder {
327
327
// 'unwinding' flag in the thread itself. For these reasons,
328
328
// this unsafety should be ok.
329
329
unsafe {
330
- unwind:: try ( move || * ptr = Some ( f. invoke ( ( ) ) ) )
330
+ unwind:: try ( move || {
331
+ let f: Thunk < ( ) , T > = f;
332
+ let v: T = f ( ) ;
333
+ * ptr = Some ( v)
334
+ } )
331
335
}
332
336
} ;
333
337
unsafe {
@@ -340,7 +344,7 @@ impl Builder {
340
344
} ;
341
345
342
346
Ok ( JoinInner {
343
- native : try!( unsafe { imp:: create ( stack_size, Thunk :: new ( main) ) } ) ,
347
+ native : try!( unsafe { imp:: create ( stack_size, Box :: new ( main) ) } ) ,
344
348
thread : my_thread,
345
349
packet : my_packet,
346
350
joined : false ,
@@ -820,7 +824,7 @@ mod test {
820
824
let x: Box < _ > = box 1 ;
821
825
let x_in_parent = ( & * x) as * const i32 as usize ;
822
826
823
- spawnfn ( Thunk :: new ( move || {
827
+ spawnfn ( Box :: new ( move || {
824
828
let x_in_child = ( & * x) as * const i32 as usize ;
825
829
tx. send ( x_in_child) . unwrap ( ) ;
826
830
} ) ) ;
@@ -832,15 +836,15 @@ mod test {
832
836
#[ test]
833
837
fn test_avoid_copying_the_body_spawn ( ) {
834
838
avoid_copying_the_body ( |v| {
835
- thread:: spawn ( move || v. invoke ( ( ) ) ) ;
839
+ thread:: spawn ( move || v ( ) ) ;
836
840
} ) ;
837
841
}
838
842
839
843
#[ test]
840
844
fn test_avoid_copying_the_body_thread_spawn ( ) {
841
845
avoid_copying_the_body ( |f| {
842
846
thread:: spawn ( move || {
843
- f. invoke ( ( ) ) ;
847
+ f ( ) ;
844
848
} ) ;
845
849
} )
846
850
}
@@ -849,7 +853,7 @@ mod test {
849
853
fn test_avoid_copying_the_body_join ( ) {
850
854
avoid_copying_the_body ( |f| {
851
855
let _ = thread:: spawn ( move || {
852
- f. invoke ( ( ) )
856
+ f ( )
853
857
} ) . join ( ) ;
854
858
} )
855
859
}
@@ -862,13 +866,13 @@ mod test {
862
866
// valgrind-friendly. try this at home, instead..!)
863
867
const GENERATIONS : u32 = 16 ;
864
868
fn child_no ( x : u32 ) -> Thunk < ' static > {
865
- return Thunk :: new ( move || {
869
+ return Box :: new ( move || {
866
870
if x < GENERATIONS {
867
- thread:: spawn ( move || child_no ( x+1 ) . invoke ( ( ) ) ) ;
871
+ thread:: spawn ( move || child_no ( x+1 ) ( ) ) ;
868
872
}
869
873
} ) ;
870
874
}
871
- thread:: spawn ( || child_no ( 0 ) . invoke ( ( ) ) ) ;
875
+ thread:: spawn ( || child_no ( 0 ) ( ) ) ;
872
876
}
873
877
874
878
#[ test]
0 commit comments