@@ -257,7 +257,7 @@ impl Builder {
257257 pub fn spawn < F > ( self , f : F ) -> io:: Result < JoinHandle > where
258258 F : FnOnce ( ) , F : Send + ' static
259259 {
260- self . spawn_inner ( Thunk :: new ( f) ) . map ( |i| JoinHandle ( i) )
260+ self . spawn_inner ( Box :: new ( f) ) . map ( |i| JoinHandle ( i) )
261261 }
262262
263263 /// Spawn a new child thread that must be joined within a given
@@ -279,7 +279,7 @@ impl Builder {
279279 pub fn scoped < ' a , T , F > ( self , f : F ) -> io:: Result < JoinGuard < ' a , T > > where
280280 T : Send + ' a , F : FnOnce ( ) -> T , F : Send + ' a
281281 {
282- self . spawn_inner ( Thunk :: new ( f) ) . map ( |inner| {
282+ self . spawn_inner ( Box :: new ( f) ) . map ( |inner| {
283283 JoinGuard { inner : inner, _marker : PhantomData }
284284 } )
285285 }
@@ -315,7 +315,7 @@ impl Builder {
315315 thread_info:: set ( imp:: guard:: current ( ) , their_thread) ;
316316 }
317317
318- let mut output = None ;
318+ let mut output: Option < T > = None ;
319319 let try_result = {
320320 let ptr = & mut output;
321321
@@ -327,7 +327,11 @@ impl Builder {
327327 // 'unwinding' flag in the thread itself. For these reasons,
328328 // this unsafety should be ok.
329329 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+ } )
331335 }
332336 } ;
333337 unsafe {
@@ -340,7 +344,7 @@ impl Builder {
340344 } ;
341345
342346 Ok ( JoinInner {
343- native : try!( unsafe { imp:: create ( stack_size, Thunk :: new ( main) ) } ) ,
347+ native : try!( unsafe { imp:: create ( stack_size, Box :: new ( main) ) } ) ,
344348 thread : my_thread,
345349 packet : my_packet,
346350 joined : false ,
@@ -820,7 +824,7 @@ mod test {
820824 let x: Box < _ > = box 1 ;
821825 let x_in_parent = ( & * x) as * const i32 as usize ;
822826
823- spawnfn ( Thunk :: new ( move || {
827+ spawnfn ( Box :: new ( move || {
824828 let x_in_child = ( & * x) as * const i32 as usize ;
825829 tx. send ( x_in_child) . unwrap ( ) ;
826830 } ) ) ;
@@ -832,15 +836,15 @@ mod test {
832836 #[ test]
833837 fn test_avoid_copying_the_body_spawn ( ) {
834838 avoid_copying_the_body ( |v| {
835- thread:: spawn ( move || v. invoke ( ( ) ) ) ;
839+ thread:: spawn ( move || v ( ) ) ;
836840 } ) ;
837841 }
838842
839843 #[ test]
840844 fn test_avoid_copying_the_body_thread_spawn ( ) {
841845 avoid_copying_the_body ( |f| {
842846 thread:: spawn ( move || {
843- f. invoke ( ( ) ) ;
847+ f ( ) ;
844848 } ) ;
845849 } )
846850 }
@@ -849,7 +853,7 @@ mod test {
849853 fn test_avoid_copying_the_body_join ( ) {
850854 avoid_copying_the_body ( |f| {
851855 let _ = thread:: spawn ( move || {
852- f. invoke ( ( ) )
856+ f ( )
853857 } ) . join ( ) ;
854858 } )
855859 }
@@ -862,13 +866,13 @@ mod test {
862866 // valgrind-friendly. try this at home, instead..!)
863867 const GENERATIONS : u32 = 16 ;
864868 fn child_no ( x : u32 ) -> Thunk < ' static > {
865- return Thunk :: new ( move || {
869+ return Box :: new ( move || {
866870 if x < GENERATIONS {
867- thread:: spawn ( move || child_no ( x+1 ) . invoke ( ( ) ) ) ;
871+ thread:: spawn ( move || child_no ( x+1 ) ( ) ) ;
868872 }
869873 } ) ;
870874 }
871- thread:: spawn ( || child_no ( 0 ) . invoke ( ( ) ) ) ;
875+ thread:: spawn ( || child_no ( 0 ) ( ) ) ;
872876 }
873877
874878 #[ test]
0 commit comments