@@ -22,26 +22,21 @@ unsafe impl Sync for Thread {}
22
22
impl Thread {
23
23
// unsafe: see thread::Builder::spawn_unchecked for safety requirements
24
24
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) ;
26
26
let mut native: libc:: pthread_t = mem:: zeroed ( ) ;
27
27
let mut attr: libc:: pthread_attr_t = mem:: zeroed ( ) ;
28
28
assert_eq ! ( libc:: pthread_attr_init( & mut attr) , 0 ) ;
29
29
30
30
let stack_size = cmp:: max ( stack, min_stack_size ( & attr) ) ;
31
31
assert_eq ! ( libc:: pthread_attr_setstacksize( & mut attr, stack_size) , 0 ) ;
32
32
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 _ ) ;
39
34
assert_eq ! ( libc:: pthread_attr_destroy( & mut attr) , 0 ) ;
40
35
41
36
return if ret != 0 {
42
37
// 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) ;
45
40
Err ( io:: Error :: from_raw_os_error ( ret) )
46
41
} else {
47
42
Ok ( Thread { id : native } )
0 commit comments