From 37bfef023dab045852ea577dbe40693147a810f5 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sun, 30 Oct 2016 09:36:04 -0600 Subject: Implement thread --- src/libstd/sys/redox/thread.rs | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'src/libstd/sys') 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) -> io::Result { 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 { None } pub unsafe fn init() -> Option { None } -- cgit 1.4.1-3-g733a5