@@ -22,26 +22,21 @@ unsafe impl Sync for Thread {}
2222impl Thread {
2323 // unsafe: see thread::Builder::spawn_unchecked for safety requirements
2424 pub unsafe fn new ( stack : usize , p : Box < dyn FnOnce ( ) > ) -> io:: Result < Thread > {
25- let mut p = mem :: ManuallyDrop :: new ( box p) ;
25+ let p = Box :: into_raw ( box p) ;
2626 let mut native: libc:: pthread_t = mem:: zeroed ( ) ;
2727 let mut attr: libc:: pthread_attr_t = mem:: zeroed ( ) ;
2828 assert_eq ! ( libc:: pthread_attr_init( & mut attr) , 0 ) ;
2929
3030 let stack_size = cmp:: max ( stack, min_stack_size ( & attr) ) ;
3131 assert_eq ! ( libc:: pthread_attr_setstacksize( & mut attr, stack_size) , 0 ) ;
3232
33- let ret = libc:: pthread_create (
34- & mut native,
35- & attr,
36- thread_start,
37- & mut * p as & mut Box < dyn FnOnce ( ) > as * mut _ as * mut _ ,
38- ) ;
33+ let ret = libc:: pthread_create ( & mut native, & attr, thread_start, p as * mut _ ) ;
3934 assert_eq ! ( libc:: pthread_attr_destroy( & mut attr) , 0 ) ;
4035
4136 return if ret != 0 {
4237 // The thread failed to start and as a result p was not consumed. Therefore, it is
43- // safe to manually drop it .
44- mem :: ManuallyDrop :: drop ( & mut p) ;
38+ // safe to reconstruct the box so that it gets deallocated .
39+ let _ = Box :: from_raw ( p) ;
4540 Err ( io:: Error :: from_raw_os_error ( ret) )
4641 } else {
4742 Ok ( Thread { id : native } )
0 commit comments