File tree Expand file tree Collapse file tree 1 file changed +12
-14
lines changed Expand file tree Collapse file tree 1 file changed +12
-14
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ use io;
15
15
use libc;
16
16
use mem;
17
17
use sys_common:: thread:: start_thread;
18
+ use sys:: cvt;
18
19
use time:: Duration ;
19
20
20
21
pub struct Thread {
@@ -30,11 +31,15 @@ impl Thread {
30
31
pub unsafe fn new < ' a > ( _stack : usize , p : Box < FnBox ( ) + ' a > ) -> io:: Result < Thread > {
31
32
let p = box p;
32
33
33
- start_thread ( & * p as * const _ as * mut _ ) ;
34
-
35
- :: sys_common:: util:: dumb_print ( format_args ! ( "thread\n " ) ) ;
36
-
37
- unimplemented ! ( ) ;
34
+ let id = cvt ( libc:: clone ( libc:: CLONE_VM | libc:: CLONE_FS | libc:: CLONE_FILES ) ) ?;
35
+ if id == 0 {
36
+ start_thread ( & * p as * const _ as * mut _ ) ;
37
+ let _ = libc:: exit ( 0 ) ;
38
+ panic ! ( "thread failed to exit" ) ;
39
+ } else {
40
+ mem:: forget ( p) ;
41
+ Ok ( Thread { id : id } )
42
+ }
38
43
}
39
44
40
45
pub fn yield_now ( ) {
@@ -69,8 +74,8 @@ impl Thread {
69
74
}
70
75
71
76
pub fn join ( self ) {
72
- :: sys_common :: util :: dumb_print ( format_args ! ( "Thread::join" ) ) ;
73
- unimplemented ! ( ) ;
77
+ let mut status = 0 ;
78
+ libc :: waitpid ( self . id , & mut status , 0 ) . unwrap ( ) ;
74
79
}
75
80
76
81
pub fn id ( & self ) -> libc:: pid_t { self . id }
@@ -82,13 +87,6 @@ impl Thread {
82
87
}
83
88
}
84
89
85
- impl Drop for Thread {
86
- fn drop ( & mut self ) {
87
- :: sys_common:: util:: dumb_print ( format_args ! ( "Thread::drop" ) ) ;
88
- unimplemented ! ( ) ;
89
- }
90
- }
91
-
92
90
pub mod guard {
93
91
pub unsafe fn current ( ) -> Option < usize > { None }
94
92
pub unsafe fn init ( ) -> Option < usize > { None }
You can’t perform that action at this time.
0 commit comments