diff options
| author | Jeremy Soller <jackpot51@gmail.com> | 2016-10-30 09:36:04 -0600 |
|---|---|---|
| committer | Jeremy Soller <jackpot51@gmail.com> | 2016-10-30 09:36:04 -0600 |
| commit | 37bfef023dab045852ea577dbe40693147a810f5 (patch) | |
| tree | 9fc8b7f11ecd36805f2d2b0da592b85cbf686b05 /src/libstd | |
| parent | ea6f5aa1b19655035475c7155441f658eeccdc5a (diff) | |
| download | rust-37bfef023dab045852ea577dbe40693147a810f5.tar.gz rust-37bfef023dab045852ea577dbe40693147a810f5.zip | |
Implement thread
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/sys/redox/thread.rs | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/src/libstd/sys/redox/thread.rs b/src/libstd/sys/redox/thread.rs index b6685f14ec7..46bc6346a6a 100644 --- a/src/libstd/sys/redox/thread.rs +++ b/src/libstd/sys/redox/thread.rs @@ -15,6 +15,7 @@ use io; use libc; use mem; use sys_common::thread::start_thread; +use sys::cvt; use time::Duration; pub struct Thread { @@ -30,11 +31,15 @@ impl Thread { pub unsafe fn new<'a>(_stack: usize, p: Box<FnBox() + 'a>) -> io::Result<Thread> { let p = box p; - start_thread(&*p as *const _ as *mut _); - - ::sys_common::util::dumb_print(format_args!("thread\n")); - - unimplemented!(); + let id = cvt(libc::clone(libc::CLONE_VM | libc::CLONE_FS | libc::CLONE_FILES))?; + if id == 0 { + start_thread(&*p as *const _ as *mut _); + let _ = libc::exit(0); + panic!("thread failed to exit"); + } else { + mem::forget(p); + Ok(Thread { id: id }) + } } pub fn yield_now() { @@ -69,8 +74,8 @@ impl Thread { } pub fn join(self) { - ::sys_common::util::dumb_print(format_args!("Thread::join")); - unimplemented!(); + let mut status = 0; + libc::waitpid(self.id, &mut status, 0).unwrap(); } pub fn id(&self) -> libc::pid_t { self.id } @@ -82,13 +87,6 @@ impl Thread { } } -impl Drop for Thread { - fn drop(&mut self) { - ::sys_common::util::dumb_print(format_args!("Thread::drop")); - unimplemented!(); - } -} - pub mod guard { pub unsafe fn current() -> Option<usize> { None } pub unsafe fn init() -> Option<usize> { None } |
