]> git.lizzy.rs Git - rust.git/commitdiff
Fallout from new thread API
authorAaron Turon <aturon@mozilla.com>
Sun, 7 Dec 2014 02:34:37 +0000 (18:34 -0800)
committerAaron Turon <aturon@mozilla.com>
Fri, 19 Dec 2014 07:31:51 +0000 (23:31 -0800)
51 files changed:
src/compiletest/runtest.rs
src/doc/guide-tasks.md
src/libcore/borrow.rs
src/librustc_driver/lib.rs
src/librustc_trans/back/write.rs
src/librustdoc/lib.rs
src/librustdoc/test.rs
src/libstd/c_str.rs
src/libstd/comm/blocking.rs
src/libstd/comm/mod.rs
src/libstd/comm/oneshot.rs
src/libstd/comm/select.rs
src/libstd/comm/shared.rs
src/libstd/comm/stream.rs
src/libstd/comm/sync.rs
src/libstd/failure.rs
src/libstd/io/comm_adapters.rs
src/libstd/io/net/pipe.rs
src/libstd/io/net/tcp.rs
src/libstd/io/process.rs
src/libstd/io/stdio.rs
src/libstd/lib.rs
src/libstd/os.rs
src/libstd/path/posix.rs
src/libstd/path/windows.rs
src/libstd/rand/os.rs
src/libstd/rt/at_exit_imp.rs
src/libstd/rt/backtrace.rs
src/libstd/rt/mod.rs
src/libstd/rt/unwind.rs
src/libstd/rt/util.rs
src/libstd/sync/future.rs
src/libstd/sync/mutex.rs
src/libstd/sync/once.rs
src/libstd/sync/poison.rs
src/libstd/sync/rwlock.rs
src/libstd/sync/task_pool.rs
src/libstd/sys/common/backtrace.rs
src/libstd/sys/common/helper_thread.rs
src/libstd/sys/common/mod.rs
src/libstd/sys/common/thread_info.rs
src/libstd/sys/common/thread_local.rs
src/libstd/sys/unix/backtrace.rs
src/libstd/sys/unix/stack_overflow.rs
src/libstd/sys/windows/stack_overflow.rs
src/libstd/task.rs
src/libstd/thread.rs
src/libstd/thread_local/mod.rs
src/libtest/lib.rs
src/test/run-pass/cleanup-rvalue-temp-during-incomplete-alloc.rs
src/test/run-pass/task-stderr.rs

index ea6f180ec39acbff6bcfca3cd8b24bd47d2c3430..1b9d98823b036d9d0b3e43819416aa1475b33005 100644 (file)
@@ -32,7 +32,7 @@
 use std::os;
 use std::str;
 use std::string::String;
-use std::task;
+use std::thread::Thread;
 use std::time::Duration;
 use test::MetricMap;
 
@@ -445,9 +445,9 @@ fn run_debuginfo_gdb_test(config: &Config, props: &TestProps, testfile: &Path) {
             loop {
                 //waiting 1 second for gdbserver start
                 timer::sleep(Duration::milliseconds(1000));
-                let result = task::try(move || {
+                let result = Thread::with_join(move || {
                     tcp::TcpStream::connect("127.0.0.1:5039").unwrap();
-                });
+                }).join();
                 if result.is_err() {
                     continue;
                 }
index 4adca43be18e946baa973d260903aedad5af58a3..4753ba7fe47033653babb1d9ef4dc78132a29ab4 100644 (file)
@@ -347,16 +347,16 @@ result with an `int` field (representing a successful result) or an `Err` result
 (representing termination with an error).
 
 ```{rust}
-# use std::task;
+# use std::thread::Thread;
 # fn some_condition() -> bool { false }
 # fn calculate_result() -> int { 0 }
-let result: Result<int, Box<std::any::Any + Send>> = task::try(move || {
+let result: Result<int, Box<std::any::Any + Send>> = Thread::with_join(move || {
     if some_condition() {
         calculate_result()
     } else {
         panic!("oops!");
     }
-});
+}).join();
 assert!(result.is_err());
 ```
 
index b44b87bd938075cc169a57c652a34c8aafc1dd43..4bf356fb552e1fa4f2562e073300dc62affa786d 100644 (file)
@@ -92,7 +92,7 @@ fn borrow_from<'b>(owned: &'b Cow<'a, T, B>) -> &'b B {
 
 /// Trait for moving into a `Cow`
 pub trait IntoCow<'a, T, Sized? B> {
-    /// Moves `self` into `Cow`
+    /// Moves `serlf` into `Cow`
     fn into_cow(self) -> Cow<'a, T, B>;
 }
 
index b0f8b3bdbe7df8970b367f2a93a00627570baef3..ba5157932b61bbf1ad9937150c08ad631813b4bd 100644 (file)
@@ -55,7 +55,7 @@
 use std::any::AnyRefExt;
 use std::io;
 use std::os;
-use std::task::TaskBuilder;
+use std::thread;
 
 use rustc::session::early_error;
 
@@ -475,18 +475,22 @@ pub fn monitor<F:FnOnce()+Send>(f: F) {
     static STACK_SIZE: uint = 32000000; // 32MB
 
     let (tx, rx) = channel();
-    let w = io::ChanWriter::new(tx);
+    let mut w = Some(io::ChanWriter::new(tx)); // option dance
     let mut r = io::ChanReader::new(rx);
 
-    let mut task = TaskBuilder::new().named("rustc").stderr(box w);
+    let mut cfg = thread::cfg().name("rustc".to_string());
 
     // FIXME: Hacks on hacks. If the env is trying to override the stack size
     // then *don't* set it explicitly.
     if os::getenv("RUST_MIN_STACK").is_none() {
-        task = task.stack_size(STACK_SIZE);
+        cfg = cfg.stack_size(STACK_SIZE);
     }
 
-    match task.try(f) {
+    let f = proc() {
+        std::io::stdio::set_stderr(box w.take().unwrap());
+        f()
+    };
+    match cfg.with_join(f).join() {
         Ok(()) => { /* fallthrough */ }
         Err(value) => {
             // Task panicked without emitting a fatal diagnostic
@@ -540,4 +544,3 @@ pub fn main() {
     let result = run(args);
     std::os::set_exit_status(result);
 }
-
index 24dfe600f2a56f2320bc5e665eac6d360789d153..8ec010a85538a917065795e7af2c2395b92ee913 100644 (file)
@@ -30,7 +30,7 @@
 use std::str;
 use std::mem;
 use std::sync::{Arc, Mutex};
-use std::task::TaskBuilder;
+use std::thread;
 use libc::{c_uint, c_int, c_void};
 
 #[deriving(Clone, PartialEq, PartialOrd, Ord, Eq)]
@@ -896,7 +896,11 @@ fn run_work_multithreaded(sess: &Session,
         let diag_emitter = diag_emitter.clone();
         let remark = sess.opts.cg.remark.clone();
 
-        let future = TaskBuilder::new().named(format!("codegen-{}", i)).try_future(move |:| {
+        let (tx, rx) = channel();
+        let mut tx = Some(tx);
+        futures.push(rx);
+
+        thread::cfg().name(format!("codegen-{}", i)).spawn(move |:| {
             let diag_handler = mk_handler(box diag_emitter);
 
             // Must construct cgcx inside the proc because it has non-Send
@@ -921,13 +925,14 @@ fn run_work_multithreaded(sess: &Session,
                     None => break,
                 }
             }
+
+            tx.take().unwrap().send(());
         });
-        futures.push(future);
     }
 
     let mut panicked = false;
-    for future in futures.into_iter() {
-        match future.into_inner() {
+    for rx in futures.into_iter() {
+        match rx.recv_opt() {
             Ok(()) => {},
             Err(_) => {
                 panicked = true;
index 3d51a6d6ab0772a40812af631645e6071b032481..9e06b4e88f5865e45690426234e9b75577418ade 100644 (file)
@@ -342,10 +342,11 @@ fn rust_input(cratefile: &str, externs: core::Externs, matches: &getopts::Matche
 
     let cr = Path::new(cratefile);
     info!("starting to run rustc");
-    let (mut krate, analysis) = std::task::try(move |:| {
+
+    let (mut krate, analysis) = std::thread::Thread::with_join(move |:| {
         let cr = cr;
         core::run_core(libs, cfgs, externs, &cr, triple)
-    }).map_err(|_| "rustc failed").unwrap();
+    }).join().map_err(|_| "rustc failed").unwrap();
     info!("finished with rustc");
     let mut analysis = Some(analysis);
     ANALYSISKEY.with(|s| {
index 0c64a0d29dffe71ba4caed1877535fdd4792e244..d004f030f36af0f531f5a2f112de79132ceab8ca 100644 (file)
@@ -16,6 +16,7 @@
 use std::str;
 use std::string::String;
 use std::thunk::Thunk;
+use std::thread::Thread;
 
 use std::collections::{HashSet, HashMap};
 use testing;
@@ -143,7 +144,7 @@ fn runtest(test: &str, cratename: &str, libs: Vec<Path>, externs: core::Externs,
     let w1 = io::ChanWriter::new(tx);
     let w2 = w1.clone();
     let old = io::stdio::set_stderr(box w1);
-    spawn(move |:| {
+    Thread::spawn(move |:| {
         let mut p = io::ChanReader::new(rx);
         let mut err = match old {
             Some(old) => {
index 27a139835c9804043b5dbf252b2f3f02a5b97db3..6bfb219d9c44e4b009581aa9196acdc6d3fdfeb6 100644 (file)
@@ -536,7 +536,7 @@ pub unsafe fn from_c_multistring<F>(buf: *const libc::c_char,
 mod tests {
     use prelude::*;
     use ptr;
-    use task;
+    use thread::Thread;
     use libc;
 
     use super::*;
@@ -637,7 +637,7 @@ fn test_iterator() {
 
     #[test]
     fn test_to_c_str_fail() {
-        assert!(task::try(move|| { "he\x00llo".to_c_str() }).is_err());
+        assert!(Thread::with_join(move|| { "he\x00llo".to_c_str() }).join().is_err());
     }
 
     #[test]
index 5e9a01d0151d02a2b2d6e47d56a57ba426229f39..bb09726575638a7892875fa32a94835c0baad34a 100644 (file)
@@ -32,7 +32,7 @@ pub struct WaitToken {
     no_send: NoSend,
 }
 
-fn token() -> (WaitToken, SignalToken) {
+pub fn tokens() -> (WaitToken, SignalToken) {
     let inner = Arc::new(Inner {
         thread: Thread::current(),
         woken: INIT_ATOMIC_BOOL,
@@ -48,7 +48,7 @@ fn token() -> (WaitToken, SignalToken) {
 }
 
 impl SignalToken {
-    fn signal(&self) -> bool {
+    pub fn signal(&self) -> bool {
         let wake = !self.inner.woken.compare_and_swap(false, true, Ordering::SeqCst);
         if wake {
             self.inner.thread.unpark();
@@ -73,7 +73,7 @@ pub unsafe fn cast_from_uint(signal_ptr: uint) -> SignalToken {
 }
 
 impl WaitToken {
-    fn wait(self) {
+    pub fn wait(self) {
         while !self.inner.woken.load(Ordering::SeqCst) {
             Thread::park()
         }
index e5ec0078c5ef0b8f8468ea56a3edfdee5f46d21b..236a055b91ea731678b17904f540a9e4daa564f2 100644 (file)
 use core::mem;
 use core::cell::UnsafeCell;
 
-pub use comm::select::{Select, Handle};
-use comm::select::StartResult::*;
+pub use self::select::{Select, Handle};
+use self::select::StartResult;
+use self::select::StartResult::*;
+use self::blocking::SignalToken;
 
 macro_rules! test {
     { fn $name:ident() $b:block $(#[$a:meta])*} => (
@@ -330,7 +332,7 @@ mod $name {
 
             use comm::*;
             use super::*;
-            use task;
+            use thread::Thread;
 
             $(#[$a])* #[test] fn f() { $b }
         }
@@ -593,12 +595,12 @@ pub fn send_opt(&self, t: T) -> Result<(), T> {
                                 (a, ret)
                             }
                             oneshot::UpDisconnected => (a, Err(t)),
-                            oneshot::UpWoke(task) => {
-                                // This send cannot panic because the task is
+                            oneshot::UpWoke(token) => {
+                                // This send cannot panic because the thread is
                                 // asleep (we're looking at it), so the receiver
                                 // can't go away.
                                 (*a.get()).send(t).ok().unwrap();
-                                task.wake().map(|t| t.reawaken());
+                                token.signal();
                                 (a, Ok(()))
                             }
                         }
@@ -937,7 +939,7 @@ fn can_recv(&self) -> bool {
         }
     }
 
-    fn start_selection(&self, mut token: SignalToken) -> bool {
+    fn start_selection(&self, mut token: SignalToken) -> StartResult {
         loop {
             let (t, new_port) = match *unsafe { self.inner() } {
                 Oneshot(ref p) => {
@@ -1240,11 +1242,11 @@ fn no_runtime() {
 
     test! { fn oneshot_single_thread_recv_chan_close() {
         // Receiving on a closed chan will panic
-        let res = task::try(move|| {
+        let res = Thread::with_join(move|| {
             let (tx, rx) = channel::<int>();
             drop(tx);
             rx.recv();
-        });
+        }).join();
         // What is our res?
         assert!(res.is_err());
     } }
@@ -1312,9 +1314,9 @@ fn no_runtime() {
         spawn(move|| {
             drop(tx);
         });
-        let res = task::try(move|| {
+        let res = Thread::with_join(move|| {
             assert!(rx.recv() == box 10);
-        });
+        }).join();
         assert!(res.is_err());
     } }
 
@@ -1334,19 +1336,19 @@ fn no_runtime() {
             spawn(move|| {
                 drop(rx);
             });
-            let _ = task::try(move|| {
+            let _ = Thread::with_join(move|| {
                 tx.send(1);
-            });
+            }).join();
         }
     } }
 
     test! { fn oneshot_multi_thread_recv_close_stress() {
         for _ in range(0, stress_factor()) {
             let (tx, rx) = channel::<int>();
-            spawn(move|| {
-                let res = task::try(move|| {
+            spawn(proc() {
+                let res = Thread::with_join(move|| {
                     rx.recv();
-                });
+                }).join();
                 assert!(res.is_err());
             });
             spawn(move|| {
@@ -1495,7 +1497,7 @@ fn recv(rx: Receiver<Box<int>>, i: int) {
             tx2.send(());
         });
         // make sure the other task has gone to sleep
-        for _ in range(0u, 5000) { task::deschedule(); }
+        for _ in range(0u, 5000) { Thread::yield_now(); }
 
         // upgrade to a shared chan and send a message
         let t = tx.clone();
@@ -1504,45 +1506,7 @@ fn recv(rx: Receiver<Box<int>>, i: int) {
 
         // wait for the child task to exit before we exit
         rx2.recv();
-    } }
-
-    test! { fn sends_off_the_runtime() {
-        use rt::thread::Thread;
-
-        let (tx, rx) = channel();
-        let t = Thread::start(move|| {
-            for _ in range(0u, 1000) {
-                tx.send(());
-            }
-        });
-        for _ in range(0u, 1000) {
-            rx.recv();
-        }
-        t.join();
-    } }
-
-    test! { fn try_recvs_off_the_runtime() {
-        use rt::thread::Thread;
-
-        let (tx, rx) = channel();
-        let (cdone, pdone) = channel();
-        let t = Thread::start(move|| {
-            let mut hits = 0u;
-            while hits < 10 {
-                match rx.try_recv() {
-                    Ok(()) => { hits += 1; }
-                    Err(Empty) => { Thread::yield_now(); }
-                    Err(Disconnected) => return,
-                }
-            }
-            cdone.send(());
-        });
-        for _ in range(0u, 10) {
-            tx.send(());
-        }
-        t.join();
-        pdone.recv();
-    } }
+    })
 }
 
 #[cfg(test)]
@@ -1700,11 +1664,11 @@ pub fn stress_factor() -> uint {
 
     test! { fn oneshot_single_thread_recv_chan_close() {
         // Receiving on a closed chan will panic
-        let res = task::try(move|| {
+        let res = Thread::with_join(move|| {
             let (tx, rx) = sync_channel::<int>(0);
             drop(tx);
             rx.recv();
-        });
+        }).join();
         // What is our res?
         assert!(res.is_err());
     } }
@@ -1777,9 +1741,9 @@ pub fn stress_factor() -> uint {
         spawn(move|| {
             drop(tx);
         });
-        let res = task::try(move|| {
+        let res = Thread::with_join(move|| {
             assert!(rx.recv() == box 10);
-        });
+        }).join();
         assert!(res.is_err());
     } }
 
@@ -1799,19 +1763,19 @@ pub fn stress_factor() -> uint {
             spawn(move|| {
                 drop(rx);
             });
-            let _ = task::try(move|| {
+            let _ = Thread::with_join(move || {
                 tx.send(1);
-            });
+            }).join();
         }
     } }
 
     test! { fn oneshot_multi_thread_recv_close_stress() {
         for _ in range(0, stress_factor()) {
             let (tx, rx) = sync_channel::<int>(0);
-            spawn(move|| {
-                let res = task::try(move|| {
+            spawn(proc() {
+                let res = Thread::with_join(move|| {
                     rx.recv();
-                });
+                }).join();
                 assert!(res.is_err());
             });
             spawn(move|| {
@@ -1960,7 +1924,7 @@ fn recv(rx: Receiver<Box<int>>, i: int) {
             tx2.send(());
         });
         // make sure the other task has gone to sleep
-        for _ in range(0u, 5000) { task::deschedule(); }
+        for _ in range(0u, 5000) { Thread::yield_now(); }
 
         // upgrade to a shared chan and send a message
         let t = tx.clone();
@@ -1971,29 +1935,6 @@ fn recv(rx: Receiver<Box<int>>, i: int) {
         rx2.recv();
     } }
 
-    test! { fn try_recvs_off_the_runtime() {
-        use rt::thread::Thread;
-
-        let (tx, rx) = sync_channel::<()>(0);
-        let (cdone, pdone) = channel();
-        let t = Thread::start(move|| {
-            let mut hits = 0u;
-            while hits < 10 {
-                match rx.try_recv() {
-                    Ok(()) => { hits += 1; }
-                    Err(Empty) => { Thread::yield_now(); }
-                    Err(Disconnected) => return,
-                }
-            }
-            cdone.send(());
-        });
-        for _ in range(0u, 10) {
-            tx.send(());
-        }
-        t.join();
-        pdone.recv();
-    } }
-
     test! { fn send_opt1() {
         let (tx, rx) = sync_channel::<int>(0);
         spawn(move|| { rx.recv(); });
@@ -2052,7 +1993,7 @@ fn recv(rx: Receiver<Box<int>>, i: int) {
     test! { fn try_send4() {
         let (tx, rx) = sync_channel::<int>(0);
         spawn(move|| {
-            for _ in range(0u, 1000) { task::deschedule(); }
+            for _ in range(0u, 1000) { Thread::yield_now(); }
             assert_eq!(tx.try_send(1), Ok(()));
         });
         assert_eq!(rx.recv(), 1);
index 68f3f229cb48783927952db50efc4b3a17a7a6e1..9c5a6518845300413c32ffb6fd2517c9856fd010 100644 (file)
@@ -39,9 +39,8 @@
 
 use core::prelude::*;
 
-use alloc::boxed::Box;
 use comm::Receiver;
-use comm::blocking::{mod, WaitToken, SignalToken};
+use comm::blocking::{mod, SignalToken};
 use core::mem;
 use sync::atomic;
 
@@ -143,7 +142,7 @@ pub fn recv(&mut self) -> Result<T, Failure<T>> {
         // Attempt to not block the task (it's a little expensive). If it looks
         // like we're not empty, then immediately go through to `try_recv`.
         if self.state.load(atomic::SeqCst) == EMPTY {
-            let (wait_token, signal_token) = blocking::token();
+            let (wait_token, signal_token) = blocking::tokens();
             let ptr = unsafe { signal_token.cast_to_uint() };
 
             // race with senders to enter the blocking state
@@ -332,7 +331,7 @@ pub fn abort_selection(&mut self) -> Result<bool, Receiver<T>> {
 
             // If we've got a blocked task, then use an atomic to gain ownership
             // of it (may fail)
-            BLOCKED => self.state.compare_and_swap(BLOCKED, EMPTY, atomic::SeqCst)
+            ptr => self.state.compare_and_swap(ptr, EMPTY, atomic::SeqCst)
         };
 
         // Now that we've got ownership of our state, figure out what to do
index 536d38c6e55086006015a288f212516464266359..690b5861c2239d94b4db607c2b6f7b196e057b6b 100644 (file)
@@ -54,7 +54,6 @@
 
 use core::prelude::*;
 
-use alloc::boxed::Box;
 use core::cell::Cell;
 use core::kinds::marker;
 use core::mem;
@@ -63,8 +62,6 @@
 use comm::Receiver;
 use comm::blocking::{mod, SignalToken};
 
-use self::StartResult::*;
-
 /// The "receiver set" of the select interface. This structure is used to manage
 /// a set of receivers which are being selected over.
 pub struct Select {
@@ -190,8 +187,8 @@ fn wait2(&self, do_preflight_checks: bool) -> uint {
             let (wait_token, signal_token) = blocking::tokens();
             for (i, handle) in self.iter().enumerate() {
                 match (*handle).packet.start_selection(signal_token.clone()) {
-                    Installed => {}
-                    Abort => {
+                    StartResult::Installed => {}
+                    StartResult::Abort => {
                         // Go back and abort the already-begun selections
                         for handle in self.iter().take(i) {
                             (*handle).packet.abort_selection();
@@ -417,10 +414,10 @@ macro_rules! select {
         let (tx3, rx3) = channel::<int>();
 
         spawn(move|| {
-            for _ in range(0u, 20) { task::deschedule(); }
+            for _ in range(0u, 20) { Thread::yield_now(); }
             tx1.send(1);
             rx3.recv();
-            for _ in range(0u, 20) { task::deschedule(); }
+            for _ in range(0u, 20) { Thread::yield_now(); }
         });
 
         select! {
@@ -440,7 +437,7 @@ macro_rules! select {
         let (tx3, rx3) = channel::<()>();
 
         spawn(move|| {
-            for _ in range(0u, 20) { task::deschedule(); }
+            for _ in range(0u, 20) { Thread::yield_now(); }
             tx1.send(1);
             tx2.send(2);
             rx3.recv();
@@ -541,7 +538,7 @@ macro_rules! select {
             tx3.send(());
         });
 
-        for _ in range(0u, 1000) { task::deschedule(); }
+        for _ in range(0u, 1000) { Thread::yield_now(); }
         drop(tx1.clone());
         tx2.send(());
         rx3.recv();
@@ -644,7 +641,7 @@ macro_rules! select {
             tx2.send(());
         });
 
-        for _ in range(0u, 100) { task::deschedule() }
+        for _ in range(0u, 100) { Thread::yield_now() }
         tx1.send(());
         rx2.recv();
     } }
@@ -663,7 +660,7 @@ macro_rules! select {
             tx2.send(());
         });
 
-        for _ in range(0u, 100) { task::deschedule() }
+        for _ in range(0u, 100) { Thread::yield_now() }
         tx1.send(());
         rx2.recv();
     } }
@@ -681,7 +678,7 @@ macro_rules! select {
             tx2.send(());
         });
 
-        for _ in range(0u, 100) { task::deschedule() }
+        for _ in range(0u, 100) { Thread::yield_now() }
         tx1.send(());
         rx2.recv();
     } }
@@ -697,7 +694,7 @@ macro_rules! select {
     test! { fn sync2() {
         let (tx, rx) = sync_channel::<int>(0);
         spawn(move|| {
-            for _ in range(0u, 100) { task::deschedule() }
+            for _ in range(0u, 100) { Thread::yield_now() }
             tx.send(1);
         });
         select! {
index 1f1ea2ca9a1b2cbeb40698e50f2ea0e97ca77801..1022694e634f607a64418f79f62f93ad61dd2dce 100644 (file)
@@ -22,7 +22,6 @@
 
 use core::prelude::*;
 
-use alloc::boxed::Box;
 use core::cmp;
 use core::int;
 
@@ -31,6 +30,7 @@
 use comm::blocking::{mod, SignalToken};
 use comm::select::StartResult;
 use comm::select::StartResult::*;
+use thread::Thread;
 
 const DISCONNECTED: int = int::MIN;
 const FUDGE: int = 1024;
index a15366d5ebc0cb700974a6195880ca32e419c4a2..b68f626060eda78ee106a8b46017ee99f58eb8f5 100644 (file)
@@ -24,7 +24,6 @@
 
 use core::prelude::*;
 
-use alloc::boxed::Box;
 use core::cmp;
 use core::int;
 use thread::Thread;
@@ -32,7 +31,7 @@
 use sync::atomic;
 use comm::spsc_queue as spsc;
 use comm::Receiver;
-use comm::blocking::{mod, WaitToken, SignalToken};
+use comm::blocking::{mod, SignalToken};
 
 const DISCONNECTED: int = int::MIN;
 #[cfg(test)]
@@ -147,7 +146,7 @@ fn take_to_wake(&mut self) -> SignalToken {
         let ptr = self.to_wake.load(atomic::SeqCst);
         self.to_wake.store(0, atomic::SeqCst);
         assert!(ptr != 0);
-        unsafe { SignaToken::cast_from_uint(ptr) }
+        unsafe { SignalToken::cast_from_uint(ptr) }
     }
 
     // Decrements the count on the channel for a sleeper, returning the sleeper
index 9e4bdb15b0037bdcf049fe5307d8a15dc3708d41..b24c6d21fba6dc2d3b190ed4c1de5b71c051c271 100644 (file)
 pub use self::Failure::*;
 use self::Blocker::*;
 
-use alloc::boxed::Box;
 use vec::Vec;
 use core::mem;
-use core::cell::UnsafeCell;
 
 use sync::{atomic, Mutex, MutexGuard};
 use comm::blocking::{mod, WaitToken, SignalToken};
@@ -105,10 +103,10 @@ pub enum Failure {
 
 /// Atomically blocks the current thread, placing it into `slot`, unlocking `lock`
 /// in the meantime. This re-locks the mutex upon returning.
-fn wait<'a, 'b, T>(lock: &'a Mutex<State<T>>,
-                   guard: MutexGuard<'b, State<T>>,
-                   f: fn(BlockedTask) -> Blocker)
-                   -> MutexGuard<'a, State<T>>
+fn wait<'a, 'b, T: Send>(lock: &'a Mutex<State<T>>,
+                         mut guard: MutexGuard<'b, State<T>>,
+                         f: fn(SignalToken) -> Blocker)
+                         -> MutexGuard<'a, State<T>>
 {
     let me: Box<Task> = Local::take();
     me.deschedule(1, |task| {
@@ -170,7 +168,7 @@ fn acquire_send_slot(&self) -> MutexGuard<State<T>> {
     }
 
     pub fn send(&self, t: T) -> Result<(), T> {
-        let guard = self.acquire_send_slot();
+        let mut guard = self.acquire_send_slot();
         if guard.disconnected { return Err(t) }
         guard.buf.enqueue(t);
 
@@ -183,7 +181,7 @@ pub fn send(&self, t: T) -> Result<(), T> {
                 let mut canceled = false;
                 assert!(guard.canceled.is_none());
                 guard.canceled = Some(unsafe { mem::transmute(&mut canceled) });
-                let guard = wait(&self.lock, guard, BlockedSender);
+                let mut guard = wait(&self.lock, guard, BlockedSender);
                 if canceled {Err(guard.buf.dequeue())} else {Ok(())}
             }
 
@@ -198,7 +196,7 @@ pub fn send(&self, t: T) -> Result<(), T> {
     }
 
     pub fn try_send(&self, t: T) -> Result<(), super::TrySendError<T>> {
-        let guard = self.lock.lock();
+        let mut guard = self.lock.lock();
         if guard.disconnected {
             Err(super::RecvDisconnected(t))
         } else if guard.buf.size() == guard.buf.cap() {
@@ -235,13 +233,13 @@ pub fn try_send(&self, t: T) -> Result<(), super::TrySendError<T>> {
     // When reading this, remember that there can only ever be one receiver at
     // time.
     pub fn recv(&self) -> Result<T, ()> {
-        let guard = self.lock.lock();
+        let mut guard = self.lock.lock();
 
         // Wait for the buffer to have something in it. No need for a while loop
         // because we're the only receiver.
         let mut waited = false;
         if !guard.disconnected && guard.buf.size() == 0 {
-            wait(&mut guard.blocker, BlockedReceiver, &self.lock);
+            guard = wait(&self.lock, guard, BlockedReceiver);
             waited = true;
         }
         if guard.disconnected && guard.buf.size() == 0 { return Err(()) }
@@ -249,12 +247,12 @@ pub fn recv(&self) -> Result<T, ()> {
         // Pick up the data, wake up our neighbors, and carry on
         assert!(guard.buf.size() > 0);
         let ret = guard.buf.dequeue();
-        self.wakeup_senders(waited, guard, state);
+        self.wakeup_senders(waited, guard);
         return Ok(ret);
     }
 
     pub fn try_recv(&self) -> Result<T, Failure> {
-        let guard = self.lock();
+        let mut guard = self.lock.lock();
 
         // Easy cases first
         if guard.disconnected { return Err(Disconnected) }
@@ -262,7 +260,7 @@ pub fn try_recv(&self) -> Result<T, Failure> {
 
         // Be sure to wake up neighbors
         let ret = Ok(guard.buf.dequeue());
-        self.wakeup_senders(false, guard, state);
+        self.wakeup_senders(false, guard);
 
         return ret;
     }
@@ -272,7 +270,7 @@ pub fn try_recv(&self) -> Result<T, Failure> {
     // * `waited` - flag if the receiver blocked to receive some data, or if it
     //              just picked up some data on the way out
     // * `guard` - the lock guard that is held over this channel's lock
-    fn wakeup_senders(&self, waited: bool, guard: MutexGuard<State<T>>) {
+    fn wakeup_senders(&self, waited: bool, mut guard: MutexGuard<State<T>>) {
         let pending_sender1: Option<SignalToken> = guard.queue.dequeue();
 
         // If this is a no-buffer channel (cap == 0), then if we didn't wait we
@@ -311,7 +309,7 @@ pub fn drop_chan(&self) {
         }
 
         // Not much to do other than wake up a receiver if one's there
-        let guard = self.lock();
+        let mut guard = self.lock.lock();
         if guard.disconnected { return }
         guard.disconnected = true;
         match mem::replace(&mut guard.blocker, NoneBlocked) {
@@ -322,7 +320,7 @@ pub fn drop_chan(&self) {
     }
 
     pub fn drop_port(&self) {
-        let guard = self.lock();
+        let mut guard = self.lock.lock();
 
         if guard.disconnected { return }
         guard.disconnected = true;
@@ -368,14 +366,14 @@ pub fn drop_port(&self) {
     // If Ok, the value is whether this port has data, if Err, then the upgraded
     // port needs to be checked instead of this one.
     pub fn can_recv(&self) -> bool {
-        let guard = self.lock();
+        let guard = self.lock.lock();
         guard.disconnected || guard.buf.size() > 0
     }
 
     // Attempts to start selection on this port. This can either succeed or fail
     // because there is data waiting.
     pub fn start_selection(&self, token: SignalToken) -> StartResult {
-        let guard = self.lock();
+        let mut guard = self.lock.lock();
         if guard.disconnected || guard.buf.size() > 0 {
             Abort
         } else {
@@ -393,7 +391,7 @@ pub fn start_selection(&self, token: SignalToken) -> StartResult {
     //
     // The return value indicates whether there's data on this port.
     pub fn abort_selection(&self) -> bool {
-        let guard = self.lock();
+        let mut guard = self.lock.lock();
         match mem::replace(&mut guard.blocker, NoneBlocked) {
             NoneBlocked => true,
             BlockedSender(token) => {
@@ -409,7 +407,7 @@ pub fn abort_selection(&self) -> bool {
 impl<T: Send> Drop for Packet<T> {
     fn drop(&mut self) {
         assert_eq!(self.channels.load(atomic::SeqCst), 0);
-        let guard = self.lock();
+        let mut guard = self.lock.lock();
         assert!(guard.queue.dequeue().is_none());
         assert!(guard.canceled.is_none());
     }
index 5438f1920d6f99423b9fede4fe49a1552d35bee8..3934b0cf45f0cc1b1e15f921a512da87360b3129 100644 (file)
 use result::Result::Ok;
 use rt::backtrace;
 use rt::util::{Stderr, Stdio};
-use rt::local::Local;
-use rt::task::Task;
 use str::Str;
 use string::String;
+use thread::Thread;
+use sys_common::thread_info;
 
 // Defined in this module instead of io::stdio so that the unwinding
 thread_local! {
@@ -52,63 +52,35 @@ pub fn on_fail(obj: &(Any+Send), file: &'static str, line: uint) {
         }
     };
     let mut err = Stderr;
-
-    // It is assumed that all reasonable rust code will have a local task at
-    // all times. This means that this `exists` will return true almost all of
-    // the time. There are border cases, however, when the runtime has
-    // *almost* set up the local task, but hasn't quite gotten there yet. In
-    // order to get some better diagnostics, we print on panic and
-    // immediately abort the whole process if there is no local task
-    // available.
-    if !Local::exists(None::<Task>) {
-        let _ = writeln!(&mut err, "panicked at '{}', {}:{}", msg, file, line);
-        if backtrace::log_enabled() {
-            let _ = backtrace::write(&mut err);
-        } else {
-            let _ = writeln!(&mut err, "run with `RUST_BACKTRACE=1` to \
-                                        see a backtrace");
-        }
-        return
-    }
-
-    // Peel the name out of local task so we can print it. We've got to be sure
-    // that the local task is in TLS while we're printing as I/O may occur.
-    let (name, unwinding) = {
-        let mut t = Local::borrow(None::<Task>);
-        (t.name.take(), t.unwinder.unwinding())
-    };
-    {
-        let n = name.as_ref().map(|n| n.as_slice()).unwrap_or("<unnamed>");
-
-        let prev = LOCAL_STDERR.with(|s| s.borrow_mut().take());
-        match prev {
-            Some(mut stderr) => {
-                // FIXME: what to do when the task printing panics?
-                let _ = writeln!(stderr,
-                                 "task '{}' panicked at '{}', {}:{}\n",
-                                 n, msg, file, line);
-                if backtrace::log_enabled() {
-                    let _ = backtrace::write(&mut *stderr);
-                }
-                let mut s = Some(stderr);
-                LOCAL_STDERR.with(|slot| {
-                    *slot.borrow_mut() = s.take();
-                });
+    let thread = Thread::current();
+    let name = thread.name().unwrap_or("<unnamed>");
+    let prev = LOCAL_STDERR.with(|s| s.borrow_mut().take());
+    match prev {
+        Some(mut stderr) => {
+            // FIXME: what to do when the thread printing panics?
+            let _ = writeln!(stderr,
+                             "thread '{}' panicked at '{}', {}:{}\n",
+                             name, msg, file, line);
+            if backtrace::log_enabled() {
+                let _ = backtrace::write(&mut *stderr);
             }
-            None => {
-                let _ = writeln!(&mut err, "task '{}' panicked at '{}', {}:{}",
-                                 n, msg, file, line);
-                if backtrace::log_enabled() {
-                    let _ = backtrace::write(&mut err);
-                }
+            let mut s = Some(stderr);
+            LOCAL_STDERR.with(|slot| {
+                *slot.borrow_mut() = s.take();
+            });
+        }
+        None => {
+            let _ = writeln!(&mut err, "thread '{}' panicked at '{}', {}:{}",
+                             name, msg, file, line);
+            if backtrace::log_enabled() {
+                let _ = backtrace::write(&mut err);
             }
         }
+    }
 
-        // If this is a double panic, make sure that we printed a backtrace
-        // for this panic.
-        if unwinding && !backtrace::log_enabled() {
-            let _ = backtrace::write(&mut err);
-        }
+    // If this is a double panic, make sure that we printed a backtrace
+    // for this panic.
+    if thread_info::panicking() && !backtrace::log_enabled() {
+        let _ = backtrace::write(&mut err);
     }
-    Local::borrow(None::<Task>).name = name;
 }
index 2aa7435d871e24c16c076423af81c6853b46975d..d2a9861737d1284260820807ddd85c0cf76ce46c 100644 (file)
@@ -156,12 +156,12 @@ mod test {
     use prelude::*;
     use super::*;
     use io;
-    use task;
+    use thread::Thread;
 
     #[test]
     fn test_rx_reader() {
         let (tx, rx) = channel();
-        task::spawn(move|| {
+        Thread::spawn(move|| {
           tx.send(vec![1u8, 2u8]);
           tx.send(vec![]);
           tx.send(vec![3u8, 4u8]);
@@ -203,7 +203,7 @@ fn test_rx_reader() {
     #[test]
     fn test_rx_buffer() {
         let (tx, rx) = channel();
-        task::spawn(move|| {
+        Thread::spawn(move|| {
           tx.send(b"he".to_vec());
           tx.send(b"llo wo".to_vec());
           tx.send(b"".to_vec());
@@ -229,7 +229,11 @@ fn test_chan_writer() {
         writer.write_be_u32(42).unwrap();
 
         let wanted = vec![0u8, 0u8, 0u8, 42u8];
+<<<<<<< HEAD
         let got = match task::try(move|| { rx.recv() }) {
+=======
+        let got = match Thread::with_join(proc() { rx.recv() }).join() {
+>>>>>>> Fallout from new thread API
             Ok(got) => got,
             Err(_) => panic!(),
         };
index 9f2f41c002108425e16c3eaa3e9bd2602ee272a8..01eb33b44f92faf4f850a83ef16e5369a4f25c43 100644 (file)
@@ -549,7 +549,7 @@ fn accept_timeout() {
                 Err(ref e) if e.kind == TimedOut => {}
                 Err(e) => panic!("error: {}", e),
             }
-            ::task::deschedule();
+            ::thread::Thread::yield_now();
             if i == 1000 { panic!("should have a pending connection") }
         }
         drop(l);
index 3c38e23183fe7e3e840ef920a15f44d6cde2afd0..0e9a93e42758c7556e15057257d879aeb795a0f6 100644 (file)
@@ -1155,7 +1155,7 @@ fn accept_timeout() {
                     Err(ref e) if e.kind == TimedOut => {}
                     Err(e) => panic!("error: {}", e),
                 }
-                ::task::deschedule();
+                ::thread::Thread::yield_now();
                 if i == 1000 { panic!("should have a pending connection") }
             }
         }
@@ -1378,7 +1378,7 @@ fn clone_while_reading() {
 
         // Try to ensure that the reading clone is indeed reading
         for _ in range(0i, 50) {
-            ::task::deschedule();
+            ::thread::Thread::yield_now();
         }
 
         // clone the handle again while it's reading, then let it finish the
index 9ba6381c8c3b3941b78400eccf0e3882c7407ff1..d9acb94714b248893a2094851df34428079ce83f 100644 (file)
@@ -30,6 +30,7 @@
 use std::hash::sip::SipState;
 use io::pipe::{PipeStream, PipePair};
 use path::BytesContainer;
+use thread::Thread;
 
 use sys;
 use sys::fs::FileDesc;
@@ -693,10 +694,12 @@ pub fn wait_with_output(mut self) -> IoResult<ProcessOutput> {
         fn read(stream: Option<io::PipeStream>) -> Receiver<IoResult<Vec<u8>>> {
             let (tx, rx) = channel();
             match stream {
-                Some(stream) => spawn(move |:| {
-                    let mut stream = stream;
-                    tx.send(stream.read_to_end())
-                }),
+                Some(stream) => {
+                    Thread::spawn(move |:| {
+                        let mut stream = stream;
+                        tx.send(stream.read_to_end())
+                    });
+                }
                 None => tx.send(Ok(Vec::new()))
             }
             rx
index 7b5cbf7d58f55170960977f2a0c06849c61ca6b5..32ba6278a8909c68834ecf3f52b86b75eab2fd53 100644 (file)
@@ -41,9 +41,6 @@
 use option::Option::{Some, None};
 use ops::{Deref, DerefMut, FnOnce};
 use result::Result::{Ok, Err};
-use rt;
-use rt::local::Local;
-use rt::task::Task;
 use slice::SliceExt;
 use str::StrPrelude;
 use string::String;
@@ -328,25 +325,17 @@ pub fn set_stderr(stderr: Box<Writer + Send>) -> Option<Box<Writer + Send>> {
 //          // io1 aliases io2
 //      })
 //  })
-fn with_task_stdout<F>(f: F) where
-    F: FnOnce(&mut Writer) -> IoResult<()>,
-{
-    let result = if Local::exists(None::<Task>) {
-        let mut my_stdout = LOCAL_STDOUT.with(|slot| {
-            slot.borrow_mut().take()
-        }).unwrap_or_else(|| {
-            box stdout() as Box<Writer + Send>
-        });
-        let result = f(&mut *my_stdout);
-        let mut var = Some(my_stdout);
-        LOCAL_STDOUT.with(|slot| {
-            *slot.borrow_mut() = var.take();
-        });
-        result
-    } else {
-        let mut io = rt::util::Stdout;
-        f(&mut io as &mut Writer)
-    };
+fn with_task_stdout(f: |&mut Writer| -> IoResult<()>) {
+    let mut my_stdout = LOCAL_STDOUT.with(|slot| {
+        slot.borrow_mut().take()
+    }).unwrap_or_else(|| {
+        box stdout() as Box<Writer + Send>
+    });
+    let result = f(&mut *my_stdout);
+    let mut var = Some(my_stdout);
+    LOCAL_STDOUT.with(|slot| {
+        *slot.borrow_mut() = var.take();
+    });
     match result {
         Ok(()) => {}
         Err(e) => panic!("failed printing to stdout: {}", e),
index a0939999c7c19945477bbe3053095bc180f9c47e..7219fef3732ea14c0b643df1822b6e0508788cbf 100644 (file)
 
 /* Threads and communication */
 
+pub mod task;
+#[allow(missing_docs)]
 pub mod thread;
 pub mod sync;
 pub mod comm;
index 550c8d2fabacaa1bc49a418e775e971ae377fab2..0ff41586e72017c02368d8ad36b46543eb6c61d8 100644 (file)
@@ -49,7 +49,7 @@
 use ptr;
 use result::Result;
 use result::Result::{Err, Ok};
-use slice::{AsSlice, SliceExt, PartialEqSliceExt};
+use slice::{AsSlice, SliceExt};
 use slice::CloneSliceExt;
 use str::{Str, StrPrelude, StrAllocating};
 use string::{String, ToString};
index f872aa8e9a4891927ae6d95ffee0227ef1f4aaa0..5ab8eb6b9422d2d679b3f654fe4a72163e0a1b07 100644 (file)
@@ -514,20 +514,20 @@ fn test_opt_paths() {
 
     #[test]
     fn test_null_byte() {
-        use task;
-        let result = task::try(move|| {
+        use thread::Thread;
+        let result = Thread::with_join(move|| {
             Path::new(b"foo/bar\0")
-        });
+        }).join();
         assert!(result.is_err());
 
-        let result = task::try(move|| {
+        let result = Thread::with_join(move|| {
             Path::new("test").set_filename(b"f\0o")
-        });
+        }).join();
         assert!(result.is_err());
 
-        let result = task::try(move|| {
+        let result = Thread::with_join(move|| {
             Path::new("test").push(b"f\0o");
-        });
+        }).join();
         assert!(result.is_err());
     }
 
index b376f6d0d5b073107c33bebe0a5b3e934ce2c716..171707c10c5da0b8627968571a837665a450ecb1 100644 (file)
@@ -1298,20 +1298,20 @@ fn test_opt_paths() {
 
     #[test]
     fn test_null_byte() {
-        use task;
-        let result = task::try(move|| {
+        use thread::Thread;
+        let result = Thread::with_join(move|| {
             Path::new(b"foo/bar\0")
-        });
+        }).join();
         assert!(result.is_err());
 
-        let result = task::try(move|| {
+        let result = Thread::with_join(move|| {
             Path::new("test").set_filename(b"f\0o")
-        });
+        }).join();
         assert!(result.is_err());
 
-        let result = task::try(move|| {
+        let result = Thread::with_join(move|| {
             Path::new("test").push(b"f\0o");
-        });
+        }).join();
         assert!(result.is_err());
     }
 
index 6bccef07131518fc9ade18aa1186f0f164c59192..d2ae66d657809af15c6129a4edcb7449848126d7 100644 (file)
@@ -340,7 +340,7 @@ mod test {
 
     use super::OsRng;
     use rand::Rng;
-    use task;
+    use thread::Thread;
 
     #[test]
     fn test_os_rng() {
@@ -360,25 +360,26 @@ fn test_os_rng_tasks() {
         for _ in range(0u, 20) {
             let (tx, rx) = channel();
             txs.push(tx);
-            task::spawn(move|| {
+
+            Thread::spawn(move|| {
                 // wait until all the tasks are ready to go.
                 rx.recv();
 
                 // deschedule to attempt to interleave things as much
                 // as possible (XXX: is this a good test?)
                 let mut r = OsRng::new().unwrap();
-                task::deschedule();
+                Thread::yield_now();
                 let mut v = [0u8, .. 1000];
 
                 for _ in range(0u, 100) {
                     r.next_u32();
-                    task::deschedule();
+                    Thread::yield_now();
                     r.next_u64();
-                    task::deschedule();
+                    Thread::yield_now();
                     r.fill_bytes(&mut v);
-                    task::deschedule();
+                    Thread::yield_now();
                 }
-            })
+            });
         }
 
         // start all the tasks
index b8012134c9ec1598d98527ba2b59b1efdf23af71..1b97a01146c4310bf7e6a4d6ac2c8771d9e3e4d5 100644 (file)
@@ -14,7 +14,6 @@
 
 use core::prelude::*;
 
-use libc;
 use boxed::Box;
 use vec::Vec;
 use sync::{Mutex, atomic, Once, ONCE_INIT};
 
 static INIT: Once = ONCE_INIT;
 static QUEUE: atomic::AtomicUint = atomic::INIT_ATOMIC_UINT;
-static RUNNING: atomic::AtomicBool = atomic::INIT_ATOMIC_BOOL;
 
 fn init() {
     let state: Box<Queue> = box Mutex::new(Vec::new());
     unsafe {
         QUEUE.store(mem::transmute(state), atomic::SeqCst);
-        libc::atexit(run);
+
+        // FIXME: switch this to use atexit as below. Currently this
+        // segfaults (the queue's memory is mysteriously gone), so
+        // instead the cleanup is tied to the `std::rt` entry point.
+        //
+        // ::libc::atexit(cleanup);
     }
 }
 
-// Note: this is private and so can only be called via atexit above,
-// which guarantees initialization.
-extern fn run() {
-    let cur = unsafe {
-        rtassert!(!RUNNING.load(atomic::SeqCst));
+pub fn cleanup() {
+    unsafe {
         let queue = QUEUE.swap(0, atomic::SeqCst);
-        rtassert!(queue != 0);
-
-        let queue: Box<Queue> = mem::transmute(queue);
-        let v = mem::replace(&mut *queue.lock(), Vec::new());
-        v
-    };
-
-    for to_run in cur.into_iter() {
-        to_run.invoke(());
+        if queue != 0 {
+            let queue: Box<Queue> = mem::transmute(queue);
+            let v = mem::replace(&mut *queue.lock(), Vec::new());
+            for to_run in v.into_iter() {
+                to_run.invoke();
+            }
+        }
     }
 }
 
@@ -60,7 +58,6 @@ pub fn push(f: Thunk) {
         // all with respect to `run`, meaning that this could theoretically be a
         // use-after-free. There's not much we can do to protect against that,
         // however. Let's just assume a well-behaved runtime and go from there!
-        rtassert!(!RUNNING.load(atomic::SeqCst));
         let queue = QUEUE.load(atomic::SeqCst);
         rtassert!(queue != 0);
         (*(queue as *const Queue)).lock().push(f);
index 40885823a0596f60e246efb8303501d38c8627a8..4a692bccf9eea61ab5170ff99f883403e4c3b33d 100644 (file)
 
 #![allow(non_camel_case_types)]
 
-use io::{IoResult, Writer};
-use iter::{Iterator, IteratorExt};
 use option::Option::{Some, None};
 use os;
-use result::Result::{Ok, Err};
-use str::{StrPrelude, from_str};
 use sync::atomic;
 
 pub use sys::backtrace::write;
index 44794d2b957ce1a40a109ec115eab0bd7f5d9a43..022e73121d7f402b910d39081984d322364d62ba 100644 (file)
 
 #![allow(dead_code)]
 
-use borrow::IntoCow;
 use failure;
 use os;
 use thunk::Thunk;
 use kinds::Send;
 use thread::Thread;
+use sys;
 use sys_common;
-use sys_common::thread::{mod, NewThread};
+use sys_common::thread_info::{mod, NewThread};
 
 // Reexport some of our utilities which are expected by other crates.
 pub use self::util::{default_sched_threads, min_stack, running_on_valgrind};
 /// Initializes global state, including frobbing
 /// the crate's logging flags, registering GC
 /// metadata, and storing the process arguments.
+// FIXME: this should be unsafe
 #[allow(experimental)]
 pub fn init(argc: int, argv: *const *const u8) {
-    // FIXME: Derefing these pointers is not safe.
-    // Need to propagate the unsafety to `start`.
     unsafe {
         args::init(argc, argv);
         thread::init();
@@ -122,8 +121,6 @@ fn lang_start(main: *const u8, argc: int, argv: *const *const u8) -> int {
 pub fn start(argc: int, argv: *const *const u8, main: Thunk) -> int {
     use prelude::*;
     use rt;
-    use rt::task::Task;
-    use str;
 
     let something_around_the_top_of_the_stack = 1;
     let addr = &something_around_the_top_of_the_stack as *const int;
@@ -153,18 +150,19 @@ pub fn start(argc: int, argv: *const *const u8, main: Thunk) -> int {
     init(argc, argv);
     let mut exit_code = None;
 
-    let thread: std::Thread = NewThread::new(Some("<main>".into_string()));
+    let thread: Thread = NewThread::new(Some("<main>".into_string()));
     thread_info::set((my_stack_bottom, my_stack_top),
                      unsafe { sys::thread::guard::main() },
                      thread);
-    unwind::try(|| {
-        unsafe {
+    let mut main_opt = Some(main); // option dance
+    unsafe {
+        let _ = unwind::try(|| {
             sys_common::stack::record_os_managed_stack_bounds(my_stack_bottom, my_stack_top);
-        }
-        (main.take().unwrap()).invoke(());
-        exit_code = Some(os::get_exit_status());
-    });
-    unsafe { cleanup(); }
+            (main_opt.take().unwrap()).invoke();
+            exit_code = Some(os::get_exit_status());
+        });
+        cleanup();
+    }
     // If the exit code wasn't set, then the task block must have panicked.
     return exit_code.unwrap_or(rt::DEFAULT_ERROR_CODE);
 }
@@ -197,14 +195,6 @@ pub fn at_exit(f: proc():Send) {
 /// undefined behavior.
 pub unsafe fn cleanup() {
     args::cleanup();
-    thread::cleanup();
-}
-
-// FIXME: these probably shouldn't be public...
-#[doc(hidden)]
-pub mod shouldnt_be_public {
-    #[cfg(not(test))]
-    pub use super::local_ptr::native::maybe_tls_key;
-    #[cfg(all(not(windows), not(target_os = "android"), not(target_os = "ios")))]
-    pub use super::local_ptr::compiled::RT_TLS_PTR;
+    sys::stack_overflow::cleanup();
+    at_exit_imp::cleanup();
 }
index decf7cfb60a2775e48cd451769bb3ef8ea72f3e9..f9f76e35bd4a0a3b4d834da468823b5eb65ffcaf 100644 (file)
@@ -565,7 +565,7 @@ fn begin_unwind_inner(msg: Box<Any + Send>, file_line: &(&'static str, uint)) ->
 
     // Now that we've run all the necessary unwind callbacks, we actually
     // perform the unwinding.
-    if thread_info::unwinding() {
+    if thread_info::panicking() {
         // If a thread panics while it's already unwinding then we
         // have limited options. Currently our preference is to
         // just abort. In the future we may consider resuming
index d3cfccab9d096b5ed7c608d4f4c0f4be6db1202d..86dbb6066f30e1097da87f678c3ba893b1e6c6e2 100644 (file)
@@ -196,8 +196,7 @@ fn write(&mut self, bytes: &[u8]) -> fmt::Result {
 }
 
 pub unsafe fn report_overflow() {
-    use rt::task::Task;
-    use rt::local::Local;
+    use thread::Thread;
 
     // See the message below for why this is not emitted to the
     // ^ Where did the message below go?
@@ -206,11 +205,6 @@ pub unsafe fn report_overflow() {
     // call would happen to initialized it (calling out to libuv),
     // and the FFI call needs 2MB of stack when we just ran out.
 
-    let task: Option<*mut Task> = Local::try_unsafe_borrow();
-
-    let name = task.and_then(|task| {
-        (*task).name.as_ref().map(|n| n.as_slice())
-    });
-
-    rterrln!("\ntask '{}' has overflowed its stack", name.unwrap_or("<unknown>"));
+    rterrln!("\nthread '{}' has overflowed its stack",
+             Thread::current().name().unwrap_or("<unknown>"));
 }
index e5a1e09967ce9d33913ad42826abfd33066a9a02..16f2cff599879d4dbff179648cd8d0088c97007b 100644 (file)
@@ -29,8 +29,8 @@
 
 use self::FutureState::*;
 use comm::{Receiver, channel};
-use task::spawn;
 use thunk::{Thunk};
+use thread::Thread;
 
 /// A type encapsulating the result of a computation which may not be complete
 pub struct Future<A> {
@@ -139,7 +139,7 @@ pub fn spawn<F>(blk: F) -> Future<A>
 
         let (tx, rx) = channel();
 
-        spawn(move |:| {
+        Thread::spawn(move |:| {
             // Don't panic if the other end has hung up
             let _ = tx.send_opt(blk());
         });
index 33f8d254c71a41e1e1f2197dbd8eef9bac45fdef..fc73e2957a55f4d96750fcd6924a2be4002eba98 100644 (file)
@@ -274,7 +274,7 @@ fn drop(&mut self) {
 mod test {
     use prelude::*;
 
-    use task;
+    use thread::Thread;
     use sync::{Arc, Mutex, StaticMutex, MUTEX_INIT, Condvar};
 
     #[test]
@@ -386,10 +386,10 @@ fn test_arc_condvar_poison() {
     fn test_mutex_arc_poison() {
         let arc = Arc::new(Mutex::new(1i));
         let arc2 = arc.clone();
-        let _ = task::try(move|| {
+        let _ = Thread::with_join(move|| {
             let lock = arc2.lock();
             assert_eq!(*lock, 2);
-        });
+        }).join();
         let lock = arc.lock();
         assert_eq!(*lock, 1);
     }
@@ -414,7 +414,7 @@ fn test_mutex_arc_nested() {
     fn test_mutex_arc_access_in_unwind() {
         let arc = Arc::new(Mutex::new(1i));
         let arc2 = arc.clone();
-        let _ = task::try(move|| -> () {
+        let _ = Thread::with_join::<()>(move|| -> () {
             struct Unwinder {
                 i: Arc<Mutex<int>>,
             }
@@ -425,7 +425,7 @@ fn drop(&mut self) {
             }
             let _u = Unwinder { i: arc2 };
             panic!();
-        });
+        }).join();
         let lock = arc.lock();
         assert_eq!(*lock, 2);
     }
index 263937c5cbec75e3941a8556301a1e4c98aa67cb..a43f822e351db7c85299139080933b51f60423e2 100644 (file)
@@ -121,7 +121,7 @@ pub fn doit<F>(&'static self, f: F) where F: FnOnce() {
 mod test {
     use prelude::*;
 
-    use task;
+    use thread::Thread;
     use super::{ONCE_INIT, Once};
 
     #[test]
@@ -143,7 +143,7 @@ fn stampede_once() {
         for _ in range(0u, 10) {
             let tx = tx.clone();
             spawn(move|| {
-                for _ in range(0u, 4) { task::deschedule() }
+                for _ in range(0u, 4) { Thread::yield_now() }
                 unsafe {
                     O.doit(|| {
                         assert!(!run);
index ee1515566204b0c545e935c8588e183aef563cbe..ad08e9873faad1ef0393bd3969c6de682e8b6306 100644 (file)
@@ -8,21 +8,19 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-use option::Option::None;
-use rustrt::task::Task;
-use rustrt::local::Local;
+use thread::Thread;
 
 pub struct Flag { pub failed: bool }
 
 impl Flag {
     pub fn borrow(&mut self) -> Guard {
-        Guard { flag: &mut self.failed, failing: failing() }
+        Guard { flag: &mut self.failed, panicking: Thread::panicking() }
     }
 }
 
 pub struct Guard<'a> {
     flag: &'a mut bool,
-    failing: bool,
+    panicking: bool,
 }
 
 impl<'a> Guard<'a> {
@@ -33,16 +31,8 @@ pub fn check(&self, name: &str) {
     }
 
     pub fn done(&mut self) {
-        if !self.failing && failing() {
+        if !self.panicking && Thread::panicking() {
             *self.flag = true;
         }
     }
 }
-
-fn failing() -> bool {
-    if Local::exists(None::<Task>) {
-        Local::borrow(None::<Task>).unwinder.unwinding()
-    } else {
-        false
-    }
-}
index b6d6aa989c58e7e163531a1f07176c21ed5a4726..1f1e9eea1d63535fa9349a05cbf9e3b267411a8b 100644 (file)
@@ -356,7 +356,7 @@ mod tests {
     use prelude::*;
 
     use rand::{mod, Rng};
-    use task;
+    use thread::Thread;
     use sync::{Arc, RWLock, StaticRWLock, RWLOCK_INIT};
 
     #[test]
@@ -409,10 +409,10 @@ fn frob() {
     fn test_rw_arc_poison_wr() {
         let arc = Arc::new(RWLock::new(1i));
         let arc2 = arc.clone();
-        let _ = task::try(move|| {
+        let _ = Thread::with_join(move|| {
             let lock = arc2.write();
             assert_eq!(*lock, 2);
-        });
+        }).join();
         let lock = arc.read();
         assert_eq!(*lock, 1);
     }
@@ -422,10 +422,10 @@ fn test_rw_arc_poison_wr() {
     fn test_rw_arc_poison_ww() {
         let arc = Arc::new(RWLock::new(1i));
         let arc2 = arc.clone();
-        let _ = task::try(move|| {
+        let _ = Thread::with_join(move|| {
             let lock = arc2.write();
             assert_eq!(*lock, 2);
-        });
+        }).join();
         let lock = arc.write();
         assert_eq!(*lock, 1);
     }
@@ -434,10 +434,10 @@ fn test_rw_arc_poison_ww() {
     fn test_rw_arc_no_poison_rr() {
         let arc = Arc::new(RWLock::new(1i));
         let arc2 = arc.clone();
-        let _ = task::try(move|| {
+        let _ = Thread::with_join(move|| {
             let lock = arc2.read();
             assert_eq!(*lock, 2);
-        });
+        }).join();
         let lock = arc.read();
         assert_eq!(*lock, 1);
     }
@@ -445,10 +445,10 @@ fn test_rw_arc_no_poison_rr() {
     fn test_rw_arc_no_poison_rw() {
         let arc = Arc::new(RWLock::new(1i));
         let arc2 = arc.clone();
-        let _ = task::try(move|| {
+        let _ = Thread::with_join(move|| {
             let lock = arc2.read();
             assert_eq!(*lock, 2);
-        });
+        }).join();
         let lock = arc.write();
         assert_eq!(*lock, 1);
     }
@@ -459,12 +459,12 @@ fn test_rw_arc() {
         let arc2 = arc.clone();
         let (tx, rx) = channel();
 
-        task::spawn(move|| {
+        Thread::spawn(move|| {
             let mut lock = arc2.write();
             for _ in range(0u, 10) {
                 let tmp = *lock;
                 *lock = -1;
-                task::deschedule();
+                Thread::yield_now();
                 *lock = tmp + 1;
             }
             tx.send(());
@@ -474,15 +474,15 @@ fn test_rw_arc() {
         let mut children = Vec::new();
         for _ in range(0u, 5) {
             let arc3 = arc.clone();
-            children.push(task::try_future(move|| {
+            children.push(Thread::with_join(move|| {
                 let lock = arc3.read();
                 assert!(*lock >= 0);
             }));
         }
 
         // Wait for children to pass their asserts
-        for r in children.iter_mut() {
-            assert!(r.get_ref().is_ok());
+        for r in children.into_iter() {
+            assert!(r.join().is_ok());
         }
 
         // Wait for writer to finish
@@ -495,7 +495,11 @@ fn test_rw_arc() {
     fn test_rw_arc_access_in_unwind() {
         let arc = Arc::new(RWLock::new(1i));
         let arc2 = arc.clone();
+<<<<<<< HEAD
         let _ = task::try(move|| -> () {
+=======
+        let _ = Thread::with_join::<()>(proc() {
+>>>>>>> Fallout from new thread API
             struct Unwinder {
                 i: Arc<RWLock<int>>,
             }
@@ -507,7 +511,7 @@ fn drop(&mut self) {
             }
             let _u = Unwinder { i: arc2 };
             panic!();
-        });
+        }).join();
         let lock = arc.read();
         assert_eq!(*lock, 2);
     }
index fa5b62a202bfdcb9223125010f6da41fd47efb33..5e7944d5fe507741a66aa2a2134406fd4841e669 100644 (file)
@@ -12,7 +12,7 @@
 
 use core::prelude::*;
 
-use task::{spawn};
+use thread::Thread;
 use comm::{channel, Sender, Receiver};
 use sync::{Arc, Mutex};
 use thunk::Thunk;
@@ -105,7 +105,7 @@ pub fn execute<F>(&self, job: F)
 }
 
 fn spawn_in_pool(jobs: Arc<Mutex<Receiver<Thunk>>>) {
-    spawn(move |:| {
+    Thread::spawn(move |:| {
         // Will spawn a new task on panic unless it is cancelled.
         let sentinel = Sentinel::new(&jobs);
 
@@ -126,7 +126,7 @@ fn spawn_in_pool(jobs: Arc<Mutex<Receiver<Thunk>>>) {
         }
 
         sentinel.cancel();
-    })
+    });
 }
 
 #[cfg(test)]
@@ -206,4 +206,3 @@ fn test_should_not_panic_on_drop_if_subtasks_panic_after_drop() {
         waiter.wait();
     }
 }
-
index 0c03060b3142dd0a97f99bde4a6539980d17bfa1..38dc516bf3d8108fb6222351d39cc118648ead1d 100644 (file)
@@ -9,7 +9,7 @@
 // except according to those terms.
 
 use io::{IoResult, Writer};
-use iter::Iterator;
+use iter::{Iterator, IteratorExt};
 use option::{Some, None};
 use result::{Ok, Err};
 use str::{StrPrelude, from_str};
index ef0181b72b0b7d88300c71f8e1173ee6b0a09f3a..8aa09d9bd30201c62b228a0170208c6522c07d68 100644 (file)
@@ -28,7 +28,7 @@
 use rt;
 use sys::helper_signal;
 
-use task;
+use thread::Thread;
 
 /// A structure for management of a helper thread.
 ///
@@ -82,7 +82,11 @@ pub fn boot<T, F>(&'static self, f: F, helper: fn(helper_signal::signal, Receive
                 *self.signal.get() = send as uint;
 
                 let t = f();
+<<<<<<< HEAD
                 task::spawn(move |:| {
+=======
+                Thread::spawn(proc() {
+>>>>>>> Fallout from new thread API
                     helper(receive, rx, t);
                     let _g = self.lock.lock();
                     *self.shutdown.get() = true;
index aeee4cf01cdd0acf4dc67b0343dac98f3e21704f..dc0ad08cdbef637100a7f8477897af5643ddcedf 100644 (file)
@@ -27,6 +27,7 @@
 pub mod rwlock;
 pub mod stack;
 pub mod thread;
+pub mod thread_info;
 pub mod thread_local;
 
 // common error constructors
index f88fd49ab99f5b61a5e33703fab782430576cf68..0612448cfa01ae43a276c0b1bef56411045b639e 100644 (file)
@@ -33,11 +33,11 @@ fn with<R>(f: |&mut ThreadInfo| -> R) -> R {
                 *c.borrow_mut() = Some(ThreadInfo {
                     stack_bounds: (0, 0),
                     stack_guard: 0,
-                    unwinder: false,
-                    thread: Thread::new(None),
+                    unwinding: false,
+                    thread: NewThread::new(None),
                 })
             }
-            f(c.borrow_mut().as_ref().unwrap())
+            f(c.borrow_mut().as_mut().unwrap())
         })
     }
 }
@@ -47,28 +47,25 @@ pub fn current_thread() -> Thread {
 }
 
 pub fn panicking() -> bool {
-    ThreadInfo::with(|info| info.unwinder.unwinding())
+    ThreadInfo::with(|info| info.unwinding)
 }
 
 pub fn stack_guard() -> uint {
     ThreadInfo::with(|info| info.stack_guard)
 }
 
-pub fn unwinding() -> bool {
-    ThreadInfo::with(|info| info.unwinder.unwinding)
-}
-
 pub fn set_unwinding(unwinding: bool) {
     ThreadInfo::with(|info| info.unwinding = unwinding)
 }
 
 pub fn set(stack_bounds: (uint, uint), stack_guard: uint, thread: Thread) {
     THREAD_INFO.with(|c| assert!(c.borrow().is_none()));
+    let mut thread_opt = Some(thread); // option dance
     THREAD_INFO.with(|c| *c.borrow_mut() = Some(ThreadInfo{
         stack_bounds: stack_bounds,
         stack_guard: stack_guard,
         unwinding: false,
-        thread: thread,
+        thread: thread_opt.take().unwrap(),
     }));
 }
 
index c3bf5cfc301c65306b7a4fc1a6bf9af195000729..fe7a7d8d0371688540bd19b327340f7a5b268afe 100644 (file)
@@ -58,7 +58,6 @@
 
 use prelude::*;
 
-use rt;
 use sync::atomic::{mod, AtomicUint};
 use sync::{Mutex, Once, ONCE_INIT};
 
index 2b36ece0e4b4867ccd0e833527def6a19e6b8ea4..5256e2cc809e4a51ce9020da2b129323f9f2cd46 100644 (file)
@@ -141,7 +141,7 @@ pub fn write(w: &mut Writer) -> IoResult<()> {
 
     struct Context<'a> {
         idx: int,
-        writer: &'a mut Writer+'a,
+        writer: &'a mut (Writer+'a),
         last_error: Option<IoError>,
     }
 
index 73b98f762b479a5b66f1889ef5e164d9b49deffd..340f95142419c043936b30e2569b6b57e710061a 100644 (file)
@@ -45,8 +45,6 @@ mod imp {
     use self::signal::{siginfo, sigaction, SIGBUS, SIG_DFL,
                        SA_SIGINFO, SA_ONSTACK, sigaltstack,
                        SIGSTKSZ};
-    use rt::local::Local;
-    use rt::task::Task;
     use libc;
     use libc::funcs::posix88::mman::{mmap, munmap};
     use libc::consts::os::posix88::{SIGSEGV,
@@ -56,20 +54,12 @@ mod imp {
                                     MAP_ANON,
                                     MAP_FAILED};
 
+    use sys_common::thread_info;
+
 
     // This is initialized in init() and only read from after
     static mut PAGE_SIZE: uint = 0;
 
-    // get_task_info is called from an exception / signal handler.
-    // It returns the guard page of the current task or 0 if that
-    // guard page doesn't exist. None is returned if there's currently
-    // no local task.
-    unsafe fn get_task_guard_page() -> Option<uint> {
-        let task: Option<*mut Task> = Local::try_unsafe_borrow();
-        task.map(|task| (&*task).stack_guard().unwrap_or(0))
-    }
-
-
     #[no_stack_check]
     unsafe extern fn signal_handler(signum: libc::c_int,
                                      info: *mut siginfo,
@@ -89,20 +79,16 @@ unsafe fn term(signum: libc::c_int) -> ! {
         // We're calling into functions with stack checks
         stack::record_sp_limit(0);
 
-        match get_task_guard_page() {
-            Some(guard) => {
-                let addr = (*info).si_addr as uint;
+        let guard = thread_info::stack_guard();
+        let addr = (*info).si_addr as uint;
 
-                if guard == 0 || addr < guard - PAGE_SIZE || addr >= guard {
-                    term(signum);
-                }
+        if guard == 0 || addr < guard - PAGE_SIZE || addr >= guard {
+            term(signum);
+        }
 
-                report_overflow();
+        report_overflow();
 
-                intrinsics::abort()
-            }
-            None => term(signum)
-        }
+        intrinsics::abort()
     }
 
     static mut MAIN_ALTSTACK: *mut libc::c_void = 0 as *mut libc::c_void;
index e3d96a054f4c678b7a27345ba5e672591b089ada..63b5b6f58637851eb78955fca417a7a2aeef1182 100644 (file)
@@ -8,15 +8,13 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-use rt::local::Local;
-use rt::task::Task;
 use rt::util::report_overflow;
 use core::prelude::*;
 use ptr;
 use mem;
 use libc;
 use libc::types::os::arch::extra::{LPVOID, DWORD, LONG, BOOL};
-use sys_common::stack;
+use sys_common::{stack, thread_info};
 
 pub struct Handler {
     _data: *mut libc::c_void
@@ -37,8 +35,7 @@ fn drop(&mut self) {}
 // guard page doesn't exist. None is returned if there's currently
 // no local task.
 unsafe fn get_task_guard_page() -> Option<uint> {
-    let task: Option<*mut Task> = Local::try_unsafe_borrow();
-    task.map(|task| (&*task).stack_guard().unwrap_or(0))
+    thread_info::stack_guard()
 }
 
 // This is initialized in init() and only read from after
index 6881a1adb25fb59de8c31e05777b9584b4d8b6db..13395fc9c7637d5e6c9421f4eea7df1bcc9047cf 100644 (file)
 
 #![deprecated = "use std::thread instead"]
 
+use any::Any;
+use boxed::Box;
 use thread;
 use kinds::Send;
+use result::Result;
 
 /// Deprecate: use `std::thread::Cfg` instead.
 #[deprecated = "use std::thread::Cfg instead"]
 pub fn spawn(f: proc(): Send) {
     thread::Thread::spawn(f);
 }
+
+/// Deprecated: use `std::thread::Thread::with_join instead`.
+#[deprecated = "use std::thread::Thread::with_join instead"]
+pub fn try<T: Send>(f: proc(): Send -> T) -> Result<T, Box<Any + Send>> {
+    thread::Thread::with_join(f).join()
+}
+
+/// Deprecated: use `std::thread::Thread::yield_now instead`.
+#[deprecated = "use std::thread::Thread::yield_now instead"]
+pub fn deschedule() {
+    thread::Thread::yield_now()
+}
index a6e114bc2c356e52184288471c0edfd39065abc4..f179219884f8becc14ad04f3cf8bb3897728182a 100644 (file)
@@ -231,7 +231,7 @@ fn core_spawn<T: Send>(self, f: proc():Send -> T, after: proc(Result<T>):Send)
             }
             thread_info::set(
                 (my_stack_bottom, my_stack_top),
-                thread::current_guard_page(),
+                unsafe { imp::guard::current() },
                 their_thread
             );
 
@@ -261,7 +261,7 @@ fn core_spawn<T: Send>(self, f: proc():Send -> T, after: proc(Result<T>):Send)
                 }
             }
         };
-        (unsafe { imp::create(stack, box main) }, my_thread)
+        (unsafe { imp::create(stack_size, box main) }, my_thread)
     }
 
     /// Spawn a detached thread, and return a handle to it.
@@ -278,19 +278,20 @@ pub fn with_join<T: Send>(self, f: proc():Send -> T) -> JoinGuard<T> {
         // We need the address of the packet to fill in to be stable so when
         // `main` fills it in it's still valid, so allocate an extra box to do
         // so.
-        let my_packet = box Err(box 0); // sentinel value
+        let any: Box<Any+Send> = box 0u8; // sentinel value
+        let my_packet = box Err(any);
         let their_packet: *mut Result<T> = unsafe {
             *mem::transmute::<&Box<Result<T>>, *const *mut Result<T>>(&my_packet)
         };
 
         let (native, thread) = self.core_spawn(f, proc(result) {
-            *their_packet = result;
+            unsafe { *their_packet = result; }
         });
 
         JoinGuard {
             native: native,
             joined: false,
-            packet: my_packet,
+            packet: Some(my_packet),
             thread: thread,
         }
     }
@@ -336,7 +337,7 @@ pub fn with_join<T: Send>(f: proc():Send -> T) -> JoinGuard<T> {
 
     /// Gets a handle to the thread that invokes it.
     pub fn current() -> Thread {
-        ThreadInfo::current_thread()
+        thread_info::current_thread()
     }
 
     /// Cooperatively give up a timeslice to the OS scheduler.
@@ -346,7 +347,7 @@ pub fn yield_now() {
 
     /// Determines whether the current thread is panicking.
     pub fn panicking() -> bool {
-        ThreadInfo::panicking()
+        thread_info::panicking()
     }
 
     // http://cr.openjdk.java.net/~stefank/6989984.1/raw_files/new/src/os/linux/vm/os_linux.cpp
@@ -355,9 +356,9 @@ pub fn panicking() -> bool {
     /// See the module doc for more detail.
     pub fn park() {
         let thread = Thread::current();
-        let guard = thread.inner.lock.lock();
+        let mut guard = thread.inner.lock.lock();
         while !*guard {
-            thread.inner.cvar.wait(guard);
+            thread.inner.cvar.wait(&guard);
         }
         *guard = false;
     }
@@ -366,7 +367,7 @@ pub fn park() {
     ///
     /// See the module doc for more detail.
     pub fn unpark(&self) {
-        let guard = self.inner.lock();
+        let mut guard = self.inner.lock.lock();
         if !*guard {
             *guard = true;
             self.inner.cvar.notify_one();
@@ -375,7 +376,7 @@ pub fn unpark(&self) {
 
     /// Get the thread's name.
     pub fn name(&self) -> Option<&str> {
-        self.inner.name.as_ref()
+        self.inner.name.as_ref().map(|s| s.as_slice())
     }
 }
 
@@ -387,7 +388,7 @@ fn new(name: Option<String>) -> Thread { Thread::new(name) }
 /// Indicates the manner in which a thread exited.
 ///
 /// A thread that completes without panicking is considered to exit successfully.
-pub type Result<T> = result::Result<T, Box<Any + Send>>;
+pub type Result<T> = ::result::Result<T, Box<Any + Send>>;
 
 #[must_use]
 /// An RAII guard that will block until thread termination when dropped.
@@ -395,7 +396,7 @@ pub struct JoinGuard<T> {
     native: imp::rust_thread,
     thread: Thread,
     joined: bool,
-    packet: Box<Result<T>>,
+    packet: Option<Box<Result<T>>>,
 }
 
 impl<T: Send> JoinGuard<T> {
index b78428d69de2153a0f244ccb7bbeb7911af1b6f9..e2cedae1be6374e0d9a09eb1b85d7f2f488f9fb7 100644 (file)
@@ -446,7 +446,7 @@ mod tests {
     use prelude::*;
 
     use cell::UnsafeCell;
-    use rt::thread::Thread;
+    use thread::Thread;
 
     struct Foo(Sender<()>);
 
@@ -534,7 +534,7 @@ fn drop(&mut self) {
             }
         }
 
-        Thread::start(move|| {
+        Thread::with_join(move|| {
             drop(S1);
         }).join();
     }
@@ -552,7 +552,7 @@ fn drop(&mut self) {
             }
         }
 
-        Thread::start(move|| unsafe {
+        Thread::with_join(move|| unsafe {
             K1.with(|s| *s.get() = Some(S1));
         }).join();
     }
index d786409e895b299cd0cea252ae3cf5769cf8e924..044a4a173c69204207c08a6eba521f6f3ccbcbb9 100644 (file)
@@ -69,7 +69,7 @@
 use std::os;
 use std::str::FromStr;
 use std::string::String;
-use std::task::TaskBuilder;
+use std::thread::{mod, Thread};
 use std::time::Duration;
 use std::thunk::{Thunk, Invoke};
 
@@ -1121,28 +1121,27 @@ fn run_test_inner(desc: TestDesc,
                       monitor_ch: Sender<MonitorMsg>,
                       nocapture: bool,
                       testfn: Thunk) {
-        spawn(move || {
+        Thread::spawn(move || {
             let (tx, rx) = channel();
             let mut reader = ChanReader::new(rx);
             let stdout = ChanWriter::new(tx.clone());
             let stderr = ChanWriter::new(tx);
-            let mut task = TaskBuilder::new().named(match desc.name {
+            let mut cfg = thread::cfg().name(match desc.name {
                 DynTestName(ref name) => name.clone().to_string(),
                 StaticTestName(name) => name.to_string(),
             });
             if nocapture {
                 drop((stdout, stderr));
             } else {
-                task = task.stdout(box stdout as Box<Writer + Send>);
-                task = task.stderr(box stderr as Box<Writer + Send>);
+                cfg = cfg.stdout(box stdout as Box<Writer + Send>);
+                cfg = cfg.stderr(box stderr as Box<Writer + Send>);
             }
-            let result_future = task.try_future(move || testfn.invoke(()));
 
+            let result_guard = cfg.with_join(testfn);
             let stdout = reader.read_to_end().unwrap().into_iter().collect();
-            let task_result = result_future.into_inner();
-            let test_result = calc_result(&desc, task_result);
+            let test_result = calc_result(&desc, result_guard.join());
             monitor_ch.send((desc.clone(), test_result, stdout));
-        })
+        });
     }
 
     match testfn {
index 771b34159f2611da7db1c9d3c0b774d1aacdc3fa..b5acb55d4a1714e0ae70d29742e3343977616a99 100644 (file)
@@ -24,7 +24,7 @@
 // It's unclear how likely such a bug is to recur, but it seems like a
 // scenario worth testing.
 
-use std::task;
+use std::thread::Thread;
 
 enum Conzabble {
     Bickwick(Foo)
@@ -45,5 +45,5 @@ pub fn fails() {
 }
 
 pub fn main() {
-    task::try(fails);
+    Thread::with_join(fails).join();
 }
index 72cf7599f89f97a0013c1f3fe0aae05c0c58a7ad..8b54de6b80553ac966559ffc13e4ffc71e45c374 100644 (file)
@@ -9,16 +9,16 @@
 // except according to those terms.
 
 use std::io::{ChanReader, ChanWriter};
-use std::task::TaskBuilder;
+use std::thread;
 
 fn main() {
     let (tx, rx) = channel();
     let mut reader = ChanReader::new(rx);
     let stderr = ChanWriter::new(tx);
 
-    let res = TaskBuilder::new().stderr(box stderr as Box<Writer + Send>).try(move|| -> () {
+    let res = thread::cfg().stderr(box stderr as Box<Writer + Send>).with_join(move|| -> () {
         panic!("Hello, world!")
-    });
+    }).join();
     assert!(res.is_err());
 
     let output = reader.read_to_string().unwrap();