From d8f8f7a58c7c8b3352c1c577347865f5a823fee3 Mon Sep 17 00:00:00 2001 From: Aaron Turon Date: Tue, 17 Feb 2015 01:08:53 -0800 Subject: [PATCH 1/2] Revise std::thread semantics This commit makes several changes to `std::thread` in preparation for final stabilization: * It removes the ability to handle panics from `scoped` children; see #20807 for discussion * It adds a `JoinHandle` structure, now returned from `spawn`, which makes it possible to join on children that do not share data from their parent's stack. The child is automatically detached when the handle is dropped, and the handle cannot be copied due to Posix semantics. * It moves all static methods from `std::thread::Thread` to free functions in `std::thread`. This was done in part because, due to the above changes, there are effectively no direct `Thread` constructors, and the static methods have tended to feel a bit awkward. * Adds an `io::Result` around the `Builder` methods `scoped` and `spawn`, making it possible to handle OS errors when creating threads. The convenience free functions entail an unwrap. * Stabilizes the entire module. Despite the fact that the API is changing somewhat here, this is part of a long period of baking and the changes are addressing all known issues prior to alpha2. If absolutely necessary, further breaking changes can be made prior to beta. Closes #20807 [breaking-change] --- src/libstd/sys/unix/thread.rs | 8 +- src/libstd/sys/windows/thread.rs | 8 +- src/libstd/thread.rs | 370 ++++++++++++++++++++++--------- 3 files changed, 273 insertions(+), 113 deletions(-) diff --git a/src/libstd/sys/unix/thread.rs b/src/libstd/sys/unix/thread.rs index 6f030ee91fe2d..82c52471d1097 100644 --- a/src/libstd/sys/unix/thread.rs +++ b/src/libstd/sys/unix/thread.rs @@ -10,6 +10,7 @@ use core::prelude::*; +use io; use boxed::Box; use cmp; use mem; @@ -191,7 +192,7 @@ pub mod guard { } } -pub unsafe fn create(stack: uint, p: Thunk) -> rust_thread { +pub unsafe fn create(stack: uint, p: Thunk) -> io::Result { let mut native: libc::pthread_t = mem::zeroed(); let mut attr: libc::pthread_attr_t = mem::zeroed(); assert_eq!(pthread_attr_init(&mut attr), 0); @@ -226,9 +227,10 @@ pub unsafe fn create(stack: uint, p: Thunk) -> rust_thread { if ret != 0 { // be sure to not leak the closure let _p: Box> = mem::transmute(arg); - panic!("failed to spawn native thread: {}", ret); + Err(io::Error::from_os_error(ret)) + } else { + Ok(native) } - native } #[cfg(any(target_os = "linux", target_os = "android"))] diff --git a/src/libstd/sys/windows/thread.rs b/src/libstd/sys/windows/thread.rs index a38dc9b2d3407..d7f86e1842eea 100644 --- a/src/libstd/sys/windows/thread.rs +++ b/src/libstd/sys/windows/thread.rs @@ -10,6 +10,7 @@ use boxed::Box; use cmp; +use io; use mem; use ptr; use libc; @@ -42,7 +43,7 @@ pub mod guard { } } -pub unsafe fn create(stack: uint, p: Thunk) -> rust_thread { +pub unsafe fn create(stack: uint, p: Thunk) -> io::Result { let arg: *mut libc::c_void = mem::transmute(box p); // FIXME On UNIX, we guard against stack sizes that are too small but // that's because pthreads enforces that stacks are at least @@ -60,9 +61,10 @@ pub unsafe fn create(stack: uint, p: Thunk) -> rust_thread { if ret as uint == 0 { // be sure to not leak the closure let _p: Box = mem::transmute(arg); - panic!("failed to spawn native thread: {:?}", ret); + Err(io::Error::last_os_error()) + } else { + Ok(ret) } - return ret; } pub unsafe fn set_name(_name: &str) { diff --git a/src/libstd/thread.rs b/src/libstd/thread.rs index cc9d7492441cd..4f667114d3815 100644 --- a/src/libstd/thread.rs +++ b/src/libstd/thread.rs @@ -58,16 +58,16 @@ //! ```rust //! use std::thread::Thread; //! -//! let thread = Thread::spawn(move || { +//! Thread::spawn(move || { //! println!("Hello, World!"); //! // some computation here //! }); //! ``` //! -//! The spawned thread is "detached" from the current thread, meaning that it -//! can outlive the thread that spawned it. (Note, however, that when the main -//! thread terminates all detached threads are terminated as well.) The returned -//! `Thread` handle can be used for low-level synchronization as described below. +//! In this example, the spawned thread is "detached" from the current +//! thread, meaning that it can outlive the thread that spawned +//! it. (Note, however, that when the main thread terminates all +//! detached threads are terminated as well.) //! //! ## Scoped threads //! @@ -86,13 +86,13 @@ //! let result = guard.join(); //! ``` //! -//! The `scoped` function doesn't return a `Thread` directly; instead, it -//! returns a *join guard* from which a `Thread` can be extracted. The join -//! guard is an RAII-style guard that will automatically join the child thread -//! (block until it terminates) when it is dropped. You can join the child -//! thread in advance by calling the `join` method on the guard, which will also -//! return the result produced by the thread. A handle to the thread itself is -//! available via the `thread` method on the join guard. +//! The `scoped` function doesn't return a `Thread` directly; instead, +//! it returns a *join guard*. The join guard is an RAII-style guard +//! that will automatically join the child thread (block until it +//! terminates) when it is dropped. You can join the child thread in +//! advance by calling the `join` method on the guard, which will also +//! return the result produced by the thread. A handle to the thread +//! itself is available via the `thread` method on the join guard. //! //! (Note: eventually, the `scoped` constructor will allow the parent and child //! threads to data that lives on the parent thread's stack, but some language @@ -151,6 +151,8 @@ use any::Any; use boxed::Box; use cell::UnsafeCell; use clone::Clone; +use fmt; +use io; use marker::{Send, Sync}; use ops::{Drop, FnOnce}; use option::Option::{self, Some, None}; @@ -224,49 +226,58 @@ impl Builder { self } - /// Spawn a new detached thread, and return a handle to it. + /// Spawn a new thread, and return a join handle for it. /// - /// See `Thead::spawn` and the module doc for more details. - #[unstable(feature = "std_misc", - reason = "may change with specifics of new Send semantics")] - pub fn spawn(self, f: F) -> Thread where F: FnOnce(), F: Send + 'static { - let (native, thread) = self.spawn_inner(Thunk::new(f), Thunk::with_arg(|_| {})); - unsafe { imp::detach(native) }; - thread + /// The child thread may outlive the parent (unless the parent thread + /// is the main thread; the whole process is terminated when the main + /// thread finishes.) The join handle can be used to block on + /// termination of the child thread, including recovering its panics. + /// + /// # Errors + /// + /// Unlike the `spawn` free function, this method yields an + /// `io::Result` to capture any failure to create the thread at + /// the OS level. + #[stable(feature = "rust1", since = "1.0.0")] + pub fn spawn(self, f: F) -> io::Result where + F: FnOnce(), F: Send + 'static + { + self.spawn_inner(Thunk::new(f)).map(|i| JoinHandle(i)) } /// Spawn a new child thread that must be joined within a given /// scope, and return a `JoinGuard`. /// - /// See `Thead::scoped` and the module doc for more details. - #[unstable(feature = "std_misc", - reason = "may change with specifics of new Send semantics")] - pub fn scoped<'a, T, F>(self, f: F) -> JoinGuard<'a, T> where + /// The join guard can be used to explicitly join the child thread (via + /// `join`), returning `Result`, or it will implicitly join the child + /// upon being dropped. Because the child thread may refer to data on the + /// current thread's stack (hence the "scoped" name), it cannot be detached; + /// it *must* be joined before the relevant stack frame is popped. See the + /// module documentation for additional details. + /// + /// # Errors + /// + /// Unlike the `scoped` free function, this method yields an + /// `io::Result` to capture any failure to create the thread at + /// the OS level. + #[stable(feature = "rust1", since = "1.0.0")] + pub fn scoped<'a, T, F>(self, f: F) -> io::Result> where T: Send + 'a, F: FnOnce() -> T, F: Send + 'a { - let my_packet = Packet(Arc::new(UnsafeCell::new(None))); - let their_packet = Packet(my_packet.0.clone()); - let (native, thread) = self.spawn_inner(Thunk::new(f), Thunk::with_arg(move |ret| unsafe { - *their_packet.0.get() = Some(ret); - })); - - JoinGuard { - native: native, - joined: false, - packet: my_packet, - thread: thread, - } + self.spawn_inner(Thunk::new(f)).map(JoinGuard) } - fn spawn_inner(self, f: Thunk<(), T>, finish: Thunk, ()>) - -> (imp::rust_thread, Thread) - { + fn spawn_inner(self, f: Thunk<(), T>) -> io::Result> { let Builder { name, stack_size, stdout, stderr } = self; let stack_size = stack_size.unwrap_or(rt::min_stack()); + let my_thread = Thread::new(name); let their_thread = my_thread.clone(); + let my_packet = Packet(Arc::new(UnsafeCell::new(None))); + let their_packet = Packet(my_packet.0.clone()); + // Spawning a new OS thread guarantees that __morestack will never get // triggered, but we must manually set up the actual stack bounds once // this function starts executing. This raises the lower limit by a bit @@ -316,17 +327,120 @@ impl Builder { unwind::try(move || *ptr = Some(f.invoke(()))) } }; - finish.invoke(match (output, try_result) { - (Some(data), Ok(_)) => Ok(data), - (None, Err(cause)) => Err(cause), - _ => unreachable!() - }); + unsafe { + *their_packet.0.get() = Some(match (output, try_result) { + (Some(data), Ok(_)) => Ok(data), + (None, Err(cause)) => Err(cause), + _ => unreachable!() + }); + } }; - (unsafe { imp::create(stack_size, Thunk::new(main)) }, my_thread) + Ok(JoinInner { + native: try!(unsafe { imp::create(stack_size, Thunk::new(main)) }), + thread: my_thread, + packet: my_packet, + joined: false, + }) + } +} + +/// Spawn a new, returning a join handle for it. +/// +/// The child thread may outlive the parent (unless the parent thread +/// is the main thread; the whole process is terminated when the main +/// thread finishes.) The join handle can be used to block on +/// termination of the child thread, including recovering its panics. +/// +/// # Panics +/// +/// Panicks if the OS fails to create a thread; use `Builder::spawn` +/// to recover from such errors. +#[stable(feature = "rust1", since = "1.0.0")] +pub fn spawn(f: F) -> JoinHandle where F: FnOnce(), F: Send + 'static { + Builder::new().spawn(f).unwrap() +} + +/// Spawn a new *scoped* thread, returning a `JoinGuard` for it. +/// +/// The join guard can be used to explicitly join the child thread (via +/// `join`), returning `Result`, or it will implicitly join the child +/// upon being dropped. Because the child thread may refer to data on the +/// current thread's stack (hence the "scoped" name), it cannot be detached; +/// it *must* be joined before the relevant stack frame is popped. See the +/// module documentation for additional details. +/// +/// # Panics +/// +/// Panicks if the OS fails to create a thread; use `Builder::scoped` +/// to recover from such errors. +#[stable(feature = "rust1", since = "1.0.0")] +pub fn scoped<'a, T, F>(f: F) -> JoinGuard<'a, T> where + T: Send + 'a, F: FnOnce() -> T, F: Send + 'a +{ + Builder::new().scoped(f).unwrap() +} + +/// Gets a handle to the thread that invokes it. +#[stable(feature = "rust1", since = "1.0.0")] +pub fn current() -> Thread { + thread_info::current_thread() +} + +/// Cooperatively give up a timeslice to the OS scheduler. +#[stable(feature = "rust1", since = "1.0.0")] +pub fn yield_now() { + unsafe { imp::yield_now() } +} + +/// Determines whether the current thread is unwinding because of panic. +#[inline] +#[stable(feature = "rust1", since = "1.0.0")] +pub fn panicking() -> bool { + unwind::panicking() +} + +/// Block unless or until the current thread's token is made available (may wake spuriously). +/// +/// See the module doc for more detail. +// +// The implementation currently uses the trivial strategy of a Mutex+Condvar +// with wakeup flag, which does not actually allow spurious wakeups. In the +// future, this will be implemented in a more efficient way, perhaps along the lines of +// http://cr.openjdk.java.net/~stefank/6989984.1/raw_files/new/src/os/linux/vm/os_linux.cpp +// or futuxes, and in either case may allow spurious wakeups. +#[stable(feature = "rust1", since = "1.0.0")] +pub fn park() { + let thread = Thread::current(); + let mut guard = thread.inner.lock.lock().unwrap(); + while !*guard { + guard = thread.inner.cvar.wait(guard).unwrap(); } + *guard = false; } +/// Block unless or until the current thread's token is made available or +/// the specified duration has been reached (may wake spuriously). +/// +/// The semantics of this function are equivalent to `park()` except that the +/// thread will be blocked for roughly no longer than dur. This method +/// should not be used for precise timing due to anomalies such as +/// preemption or platform differences that may not cause the maximum +/// amount of time waited to be precisely dur +/// +/// See the module doc for more detail. +#[unstable(feature = "std_misc", reason = "recently introduced, depends on Duration")] +pub fn park_timeout(dur: Duration) { + let thread = Thread::current(); + let mut guard = thread.inner.lock.lock().unwrap(); + if !*guard { + let (g, _) = thread.inner.cvar.wait_timeout(guard, dur).unwrap(); + guard = g; + } + *guard = false; +} + +/// The internal representation of a `Thread` handle struct Inner { name: Option, lock: Mutex, // true when there is a buffered unpark @@ -354,62 +468,48 @@ impl Thread { } } - /// Spawn a new detached thread, returning a handle to it. - /// - /// The child thread may outlive the parent (unless the parent thread is the - /// main thread; the whole process is terminated when the main thread - /// finishes.) The thread handle can be used for low-level - /// synchronization. See the module documentation for additional details. + /// Deprecated: use module-level free fucntion. + #[deprecated(since = "1.0.0", reason = "use module-level free fucntion")] #[unstable(feature = "std_misc", reason = "may change with specifics of new Send semantics")] pub fn spawn(f: F) -> Thread where F: FnOnce(), F: Send + 'static { - Builder::new().spawn(f) + Builder::new().spawn(f).unwrap().thread().clone() } - /// Spawn a new *scoped* thread, returning a `JoinGuard` for it. - /// - /// The join guard can be used to explicitly join the child thread (via - /// `join`), returning `Result`, or it will implicitly join the child - /// upon being dropped. Because the child thread may refer to data on the - /// current thread's stack (hence the "scoped" name), it cannot be detached; - /// it *must* be joined before the relevant stack frame is popped. See the - /// module documentation for additional details. + /// Deprecated: use module-level free fucntion. + #[deprecated(since = "1.0.0", reason = "use module-level free fucntion")] #[unstable(feature = "std_misc", reason = "may change with specifics of new Send semantics")] pub fn scoped<'a, T, F>(f: F) -> JoinGuard<'a, T> where T: Send + 'a, F: FnOnce() -> T, F: Send + 'a { - Builder::new().scoped(f) + Builder::new().scoped(f).unwrap() } - /// Gets a handle to the thread that invokes it. + /// Deprecated: use module-level free fucntion. + #[deprecated(since = "1.0.0", reason = "use module-level free fucntion")] #[stable(feature = "rust1", since = "1.0.0")] pub fn current() -> Thread { thread_info::current_thread() } - /// Cooperatively give up a timeslice to the OS scheduler. + /// Deprecated: use module-level free fucntion. + #[deprecated(since = "1.0.0", reason = "use module-level free fucntion")] #[unstable(feature = "std_misc", reason = "name may change")] pub fn yield_now() { unsafe { imp::yield_now() } } - /// Determines whether the current thread is unwinding because of panic. + /// Deprecated: use module-level free fucntion. + #[deprecated(since = "1.0.0", reason = "use module-level free fucntion")] #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub fn panicking() -> bool { unwind::panicking() } - /// Block unless or until the current thread's token is made available (may wake spuriously). - /// - /// See the module doc for more detail. - // - // The implementation currently uses the trivial strategy of a Mutex+Condvar - // with wakeup flag, which does not actually allow spurious wakeups. In the - // future, this will be implemented in a more efficient way, perhaps along the lines of - // http://cr.openjdk.java.net/~stefank/6989984.1/raw_files/new/src/os/linux/vm/os_linux.cpp - // or futuxes, and in either case may allow spurious wakeups. + /// Deprecated: use module-level free fucntion. + #[deprecated(since = "1.0.0", reason = "use module-level free fucntion")] #[unstable(feature = "std_misc", reason = "recently introduced")] pub fn park() { let thread = Thread::current(); @@ -420,16 +520,8 @@ impl Thread { *guard = false; } - /// Block unless or until the current thread's token is made available or - /// the specified duration has been reached (may wake spuriously). - /// - /// The semantics of this function are equivalent to `park()` except that the - /// thread will be blocked for roughly no longer than dur. This method - /// should not be used for precise timing due to anomalies such as - /// preemption or platform differences that may not cause the maximum - /// amount of time waited to be precisely dur - /// - /// See the module doc for more detail. + /// Deprecated: use module-level free fucntion. + #[deprecated(since = "1.0.0", reason = "use module-level free fucntion")] #[unstable(feature = "std_misc", reason = "recently introduced")] pub fn park_timeout(dur: Duration) { let thread = Thread::current(); @@ -444,7 +536,7 @@ impl Thread { /// Atomically makes the handle's token available if it is not already. /// /// See the module doc for more detail. - #[unstable(feature = "std_misc", reason = "recently introduced")] + #[stable(feature = "rust1", since = "1.0.0")] pub fn unpark(&self) { let mut guard = self.inner.lock.lock().unwrap(); if !*guard { @@ -460,6 +552,13 @@ impl Thread { } } +#[stable(feature = "rust1", since = "1.0.0")] +impl fmt::Debug for Thread { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(&self.name(), f) + } +} + // a hack to get around privacy restrictions impl thread_info::NewThread for Thread { fn new(name: Option) -> Thread { Thread::new(name) } @@ -476,19 +575,76 @@ struct Packet(Arc>>>); unsafe impl Send for Packet {} unsafe impl Sync for Packet {} -/// An RAII-style guard that will block until thread termination when dropped. -/// -/// The type `T` is the return type for the thread's main function. -#[must_use] -#[unstable(feature = "std_misc", - reason = "may change with specifics of new Send semantics")] -pub struct JoinGuard<'a, T: 'a> { +/// Inner representation for JoinHandle and JoinGuard +struct JoinInner { native: imp::rust_thread, thread: Thread, - joined: bool, packet: Packet, + joined: bool, } +impl JoinInner { + fn join(&mut self) -> Result { + assert!(!self.joined); + unsafe { imp::join(self.native) }; + self.joined = true; + unsafe { + (*self.packet.0.get()).take().unwrap() + } + } +} + +/// An owned permission to join on a thread (block on its termination). +/// +/// Unlike a `JoinGuard`, a `JoinHandle` *detaches* the child thread +/// when it is dropped, rather than automatically joining on drop. +/// +/// Due to platform restrictions, it is not possible to `Clone` this +/// handle: the ability to join a child thread is a uniquely-owned +/// permission. +#[stable(feature = "rust1", since = "1.0.0")] +pub struct JoinHandle(JoinInner<()>); + +impl JoinHandle { + /// Extract a handle to the underlying thread + #[stable(feature = "rust1", since = "1.0.0")] + pub fn thread(&self) -> &Thread { + &self.0.thread + } + + /// Wait for the associated thread to finish. + /// + /// If the child thread panics, `Err` is returned with the parameter given + /// to `panic`. + #[stable(feature = "rust1", since = "1.0.0")] + pub fn join(mut self) -> Result<()> { + self.0.join() + } +} + +#[stable(feature = "rust1", since = "1.0.0")] +impl Drop for JoinHandle { + fn drop(&mut self) { + if !self.0.joined { + unsafe { imp::detach(self.0.native) } + } + } +} + +/// An RAII-style guard that will block until thread termination when dropped. +/// +/// The type `T` is the return type for the thread's main function. +/// +/// Joining on drop is necessary to ensure memory safety when stack +/// data is shared between a parent and child thread. +/// +/// Due to platform restrictions, it is not possible to `Clone` this +/// handle: the ability to join a child thread is a uniquely-owned +/// permission. +#[must_use] +#[stable(feature = "rust1", since = "1.0.0")] +pub struct JoinGuard<'a, T: 'a>(JoinInner); + #[stable(feature = "rust1", since = "1.0.0")] unsafe impl<'a, T: Send + 'a> Sync for JoinGuard<'a, T> {} @@ -496,32 +652,32 @@ impl<'a, T: Send + 'a> JoinGuard<'a, T> { /// Extract a handle to the thread this guard will join on. #[stable(feature = "rust1", since = "1.0.0")] pub fn thread(&self) -> &Thread { - &self.thread + &self.0.thread } /// Wait for the associated thread to finish, returning the result of the thread's /// calculation. /// - /// If the child thread panics, `Err` is returned with the parameter given - /// to `panic`. + /// # Panics + /// + /// Panics on the child thread are propagated by panicking the parent. #[stable(feature = "rust1", since = "1.0.0")] - pub fn join(mut self) -> Result { - assert!(!self.joined); - unsafe { imp::join(self.native) }; - self.joined = true; - unsafe { - (*self.packet.0.get()).take().unwrap() + pub fn join(mut self) -> T { + match self.0.join() { + Ok(res) => res, + Err(_) => panic!("child thread {:?} panicked", self.thread()), } } } +#[stable(feature = "rust1", since = "1.0.0")] impl JoinGuard<'static, T> { /// Detaches the child thread, allowing it to outlive its parent. - #[unstable(feature = "std_misc", - reason = "unsure whether this API imposes limitations elsewhere")] + #[deprecated(since = "1.0.0", reason = "use spawn instead")] + #[unstable(feature = "std_misc")] pub fn detach(mut self) { - unsafe { imp::detach(self.native) }; - self.joined = true; // avoid joining in the destructor + unsafe { imp::detach(self.0.native) }; + self.0.joined = true; // avoid joining in the destructor } } @@ -529,8 +685,8 @@ impl JoinGuard<'static, T> { #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T: Send + 'a> Drop for JoinGuard<'a, T> { fn drop(&mut self) { - if !self.joined { - unsafe { imp::join(self.native) }; + if !self.0.joined { + unsafe { imp::join(self.0.native) }; } } } From d0de2b46e9bcca93971ef64d6ecdef872633f246 Mon Sep 17 00:00:00 2001 From: Aaron Turon Date: Tue, 17 Feb 2015 15:10:25 -0800 Subject: [PATCH 2/2] Fallout from stabilization --- src/compiletest/runtest.rs | 4 +- src/liballoc/arc.rs | 16 +- src/libcollections/dlist.rs | 4 +- src/libcore/atomic.rs | 4 +- src/libcore/cell.rs | 8 +- src/libcoretest/finally.rs | 6 +- src/librustdoc/lib.rs | 2 +- src/librustdoc/test.rs | 4 +- src/libstd/macros.rs | 6 +- src/libstd/net/tcp.rs | 76 ++++----- src/libstd/net/udp.rs | 16 +- src/libstd/old_io/comm_adapters.rs | 8 +- src/libstd/old_io/mod.rs | 4 +- src/libstd/old_io/net/pipe.rs | 54 +++--- src/libstd/old_io/net/tcp.rs | 128 +++++++-------- src/libstd/old_io/net/udp.rs | 20 +-- src/libstd/old_io/pipe.rs | 4 +- src/libstd/old_io/process.rs | 10 +- src/libstd/old_io/stdio.rs | 6 +- src/libstd/old_io/timer.rs | 10 +- src/libstd/old_path/posix.rs | 8 +- src/libstd/old_path/windows.rs | 8 +- src/libstd/panicking.rs | 4 +- src/libstd/process.rs | 6 +- src/libstd/rand/os.rs | 12 +- src/libstd/rt/util.rs | 4 +- src/libstd/sync/barrier.rs | 8 +- src/libstd/sync/condvar.rs | 16 +- src/libstd/sync/future.rs | 8 +- src/libstd/sync/mpsc/blocking.rs | 6 +- src/libstd/sync/mpsc/mod.rs | 154 +++++++++--------- src/libstd/sync/mpsc/mpsc_queue.rs | 4 +- src/libstd/sync/mpsc/select.rs | 42 ++--- src/libstd/sync/mpsc/shared.rs | 8 +- src/libstd/sync/mpsc/spsc_queue.rs | 4 +- src/libstd/sync/mpsc/stream.rs | 4 +- src/libstd/sync/mutex.rs | 24 +-- src/libstd/sync/once.rs | 6 +- src/libstd/sync/poison.rs | 6 +- src/libstd/sync/rwlock.rs | 20 +-- src/libstd/sync/semaphore.rs | 12 +- src/libstd/sync/task_pool.rs | 4 +- src/libstd/sys/common/helper_thread.rs | 4 +- src/libstd/sys/common/thread_info.rs | 4 +- src/libstd/sys/common/thread_local.rs | 2 +- src/libstd/thread.rs | 102 +++++++----- src/libstd/thread_local/mod.rs | 18 +- src/libstd/thread_local/scoped.rs | 12 +- src/libtest/lib.rs | 2 +- src/test/auxiliary/cci_capture_clause.rs | 4 +- src/test/bench/msgsend-pipes-shared.rs | 6 +- src/test/bench/msgsend-pipes.rs | 8 +- src/test/bench/rt-messaging-ping-pong.rs | 6 +- src/test/bench/rt-parfib.rs | 4 +- src/test/bench/shootout-binarytrees.rs | 2 +- src/test/bench/shootout-chameneos-redux.rs | 4 +- src/test/bench/shootout-fannkuch-redux.rs | 4 +- src/test/bench/shootout-k-nucleotide-pipes.rs | 4 +- src/test/bench/shootout-k-nucleotide.rs | 6 +- src/test/bench/shootout-mandelbrot.rs | 6 +- src/test/bench/shootout-meteor.rs | 4 +- src/test/bench/shootout-pfib.rs | 10 +- src/test/bench/shootout-reverse-complement.rs | 4 +- src/test/bench/shootout-spectralnorm.rs | 4 +- src/test/bench/shootout-threadring.rs | 6 +- src/test/bench/task-perf-alloc-unwind.rs | 4 +- .../bench/task-perf-jargon-metal-smoke.rs | 6 +- src/test/bench/task-perf-spawnalot.rs | 6 +- .../borrowck-loan-blocks-move-cc.rs | 6 +- .../borrowck-multiple-captures.rs | 10 +- src/test/compile-fail/issue-12041.rs | 4 +- src/test/compile-fail/issue-8460-const.rs | 42 ++--- src/test/compile-fail/missing-stability.rs | 2 +- .../moves-based-on-type-capture-clause-bad.rs | 4 +- src/test/compile-fail/no-capture-arc.rs | 4 +- src/test/compile-fail/no-reuse-move-arc.rs | 4 +- src/test/compile-fail/no-send-res-ports.rs | 4 +- src/test/run-fail/panic-task-name-none.rs | 4 +- .../run-fail/rt-set-exit-status-panic2.rs | 4 +- src/test/run-fail/task-spawn-barefn.rs | 4 +- src/test/run-pass/unique-send-2.rs | 4 +- .../run-pass/unit-like-struct-drop-run.rs | 4 +- src/test/run-pass/unwind-resource.rs | 4 +- src/test/run-pass/unwind-unique.rs | 4 +- src/test/run-pass/vector-sort-panic-safe.rs | 4 +- src/test/run-pass/weak-lang-item.rs | 4 +- src/test/run-pass/yield.rs | 10 +- src/test/run-pass/yield1.rs | 6 +- src/test/run-pass/yield2.rs | 4 +- 89 files changed, 578 insertions(+), 558 deletions(-) diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs index 5a372fd7cdcb2..a5aa480ab50a0 100644 --- a/src/compiletest/runtest.rs +++ b/src/compiletest/runtest.rs @@ -35,7 +35,7 @@ use std::env; use std::iter::repeat; use std::str; use std::string::String; -use std::thread::Thread; +use std::thread; use std::time::Duration; use test::MetricMap; @@ -447,7 +447,7 @@ 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 = Thread::scoped(move || { + let result = thread::spawn(move || { tcp::TcpStream::connect("127.0.0.1:5039").unwrap(); }).join(); if result.is_err() { diff --git a/src/liballoc/arc.rs b/src/liballoc/arc.rs index 0617c604121f4..3830d7fe29532 100644 --- a/src/liballoc/arc.rs +++ b/src/liballoc/arc.rs @@ -35,14 +35,14 @@ //! //! ``` //! use std::sync::Arc; -//! use std::thread::Thread; +//! use std::thread; //! //! let five = Arc::new(5); //! //! for _ in 0..10 { //! let five = five.clone(); //! -//! Thread::spawn(move || { +//! thread::spawn(move || { //! println!("{:?}", five); //! }); //! } @@ -52,14 +52,14 @@ //! //! ``` //! use std::sync::{Arc, Mutex}; -//! use std::thread::Thread; +//! use std::thread; //! //! let five = Arc::new(Mutex::new(5)); //! //! for _ in 0..10 { //! let five = five.clone(); //! -//! Thread::spawn(move || { +//! thread::spawn(move || { //! let mut number = five.lock().unwrap(); //! //! *number += 1; @@ -95,7 +95,7 @@ use heap::deallocate; /// /// ```rust /// use std::sync::Arc; -/// use std::thread::Thread; +/// use std::thread; /// /// fn main() { /// let numbers: Vec<_> = (0..100u32).map(|i| i as f32).collect(); @@ -104,7 +104,7 @@ use heap::deallocate; /// for _ in 0..10 { /// let child_numbers = shared_numbers.clone(); /// -/// Thread::spawn(move || { +/// thread::spawn(move || { /// let local_numbers = child_numbers.as_slice(); /// /// // Work with the local numbers @@ -621,7 +621,7 @@ mod tests { use std::option::Option::{Some, None}; use std::sync::atomic; use std::sync::atomic::Ordering::{Acquire, SeqCst}; - use std::thread::Thread; + use std::thread; use std::vec::Vec; use super::{Arc, Weak, weak_count, strong_count}; use std::sync::Mutex; @@ -648,7 +648,7 @@ mod tests { let (tx, rx) = channel(); - let _t = Thread::spawn(move || { + let _t = thread::spawn(move || { let arc_v: Arc> = rx.recv().unwrap(); assert_eq!((*arc_v)[3], 4); }); diff --git a/src/libcollections/dlist.rs b/src/libcollections/dlist.rs index 423646e5acd04..7174b4d4665e7 100644 --- a/src/libcollections/dlist.rs +++ b/src/libcollections/dlist.rs @@ -935,7 +935,7 @@ mod tests { use prelude::*; use std::rand; use std::hash::{self, SipHasher}; - use std::thread::Thread; + use std::thread; use test::Bencher; use test; @@ -1284,7 +1284,7 @@ mod tests { #[test] fn test_send() { let n = list_from(&[1,2,3]); - Thread::scoped(move || { + thread::spawn(move || { check_links(&n); let a: &[_] = &[&1,&2,&3]; assert_eq!(a, n.iter().collect::>()); diff --git a/src/libcore/atomic.rs b/src/libcore/atomic.rs index 32e8cffcae4f9..05d864accc130 100644 --- a/src/libcore/atomic.rs +++ b/src/libcore/atomic.rs @@ -42,13 +42,13 @@ //! ``` //! use std::sync::Arc; //! use std::sync::atomic::{AtomicUsize, Ordering}; -//! use std::thread::Thread; +//! use std::thread; //! //! fn main() { //! let spinlock = Arc::new(AtomicUsize::new(1)); //! //! let spinlock_clone = spinlock.clone(); -//! Thread::spawn(move|| { +//! thread::spawn(move|| { //! spinlock_clone.store(0, Ordering::SeqCst); //! }); //! diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index cf293ded13f00..a1c3d58f23518 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -375,9 +375,9 @@ impl RefCell { /// /// ``` /// use std::cell::RefCell; - /// use std::thread::Thread; + /// use std::thread; /// - /// let result = Thread::scoped(move || { + /// let result = thread::spawn(move || { /// let c = RefCell::new(5); /// let m = c.borrow_mut(); /// @@ -436,9 +436,9 @@ impl RefCell { /// /// ``` /// use std::cell::RefCell; - /// use std::thread::Thread; + /// use std::thread; /// - /// let result = Thread::scoped(move || { + /// let result = thread::spawn(move || { /// let c = RefCell::new(5); /// let m = c.borrow_mut(); /// diff --git a/src/libcoretest/finally.rs b/src/libcoretest/finally.rs index 42c2dfbda082a..55fcb8498513c 100644 --- a/src/libcoretest/finally.rs +++ b/src/libcoretest/finally.rs @@ -11,7 +11,7 @@ #![allow(deprecated)] use core::finally::{try_finally, Finally}; -use std::thread::Thread; +use std::thread; #[test] fn test_success() { @@ -22,7 +22,7 @@ fn test_success() { *i = 10; }, |i| { - assert!(!Thread::panicking()); + assert!(!thread::panicking()); assert_eq!(*i, 10); *i = 20; }); @@ -40,7 +40,7 @@ fn test_fail() { panic!(); }, |i| { - assert!(Thread::panicking()); + assert!(thread::panicking()); assert_eq!(*i, 10); }) } diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index b09c3f730fc64..91614409bfa04 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -365,7 +365,7 @@ 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::thread::Thread::scoped(move || { + let (mut krate, analysis) = std::thread::spawn(move || { use rustc::session::config::Input; let cr = cr; diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index 09df9fc8cbb66..bf14b86ebd1e3 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -15,7 +15,7 @@ use std::old_io::{Command, TempDir}; use std::old_io; use std::env; use std::str; -use std::thread::Thread; +use std::thread; use std::thunk::Thunk; use std::collections::{HashSet, HashMap}; @@ -142,7 +142,7 @@ fn runtest(test: &str, cratename: &str, libs: SearchPaths, let w1 = old_io::ChanWriter::new(tx); let w2 = w1.clone(); let old = old_io::stdio::set_stderr(box w1); - Thread::spawn(move || { + thread::spawn(move || { let mut p = old_io::ChanReader::new(rx); let mut err = match old { Some(old) => { diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index 6a2aafcf8f396..1b9b13d4bd401 100644 --- a/src/libstd/macros.rs +++ b/src/libstd/macros.rs @@ -126,7 +126,7 @@ macro_rules! try { /// # Examples /// /// ``` -/// use std::thread::Thread; +/// use std::thread; /// use std::sync::mpsc; /// /// // two placeholder functions for now @@ -136,8 +136,8 @@ macro_rules! try { /// let (tx1, rx1) = mpsc::channel(); /// let (tx2, rx2) = mpsc::channel(); /// -/// Thread::spawn(move|| { long_running_task(); tx1.send(()).unwrap(); }); -/// Thread::spawn(move|| { tx2.send(calculate_the_answer()).unwrap(); }); +/// thread::spawn(move|| { long_running_task(); tx1.send(()).unwrap(); }); +/// thread::spawn(move|| { tx2.send(calculate_the_answer()).unwrap(); }); /// /// select! ( /// _ = rx1.recv() => println!("the long running task finished first"), diff --git a/src/libstd/net/tcp.rs b/src/libstd/net/tcp.rs index 50eafdfc5c238..805239f6fa4d3 100644 --- a/src/libstd/net/tcp.rs +++ b/src/libstd/net/tcp.rs @@ -43,7 +43,7 @@ pub struct TcpStream(net_imp::TcpStream); /// /// ```no_run /// use std::net::{TcpListener, TcpStream}; -/// use std::thread::Thread; +/// use std::thread; /// /// let listener = TcpListener::bind("127.0.0.1:80").unwrap(); /// @@ -55,7 +55,7 @@ pub struct TcpStream(net_imp::TcpStream); /// for stream in listener.incoming() { /// match stream { /// Ok(stream) => { -/// Thread::spawn(move|| { +/// thread::spawn(move|| { /// // connection succeeded /// handle_client(stream) /// }); @@ -217,7 +217,7 @@ mod tests { use net::*; use net::test::{next_test_ip4, next_test_ip6}; use sync::mpsc::channel; - use thread::Thread; + use thread; fn each_ip(f: &mut FnMut(SocketAddr)) { f(next_test_ip4()); @@ -256,7 +256,7 @@ mod tests { let socket_addr = next_test_ip4(); let listener = t!(TcpListener::bind(&socket_addr)); - let _t = Thread::scoped(move || { + let _t = thread::spawn(move || { let mut stream = t!(TcpStream::connect(&("localhost", socket_addr.port()))); t!(stream.write(&[144])); @@ -273,7 +273,7 @@ mod tests { let addr = next_test_ip4(); let acceptor = t!(TcpListener::bind(&addr)); - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { let mut stream = t!(TcpStream::connect(&("127.0.0.1", addr.port()))); t!(stream.write(&[44])); }); @@ -289,7 +289,7 @@ mod tests { let addr = next_test_ip6(); let acceptor = t!(TcpListener::bind(&addr)); - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { let mut stream = t!(TcpStream::connect(&("::1", addr.port()))); t!(stream.write(&[66])); }); @@ -306,7 +306,7 @@ mod tests { let acceptor = t!(TcpListener::bind(&addr)); let (tx, rx) = channel(); - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { let mut stream = t!(TcpStream::connect(&addr)); t!(stream.write(&[99])); tx.send(t!(stream.socket_addr())).unwrap(); @@ -325,7 +325,7 @@ mod tests { each_ip(&mut |addr| { let acceptor = t!(TcpListener::bind(&addr)); - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { let _stream = t!(TcpStream::connect(&addr)); // Close }); @@ -345,7 +345,7 @@ mod tests { let acceptor = t!(TcpListener::bind(&addr)); let (tx, rx) = channel(); - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { drop(t!(TcpStream::connect(&addr))); tx.send(()).unwrap(); }); @@ -371,7 +371,7 @@ mod tests { let max = 10; let acceptor = t!(TcpListener::bind(&addr)); - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { for _ in 0..max { let mut stream = t!(TcpStream::connect(&addr)); t!(stream.write(&[99])); @@ -393,11 +393,11 @@ mod tests { each_ip(&mut |addr| { let acceptor = t!(TcpListener::bind(&addr)); - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { let acceptor = acceptor; for (i, stream) in acceptor.incoming().enumerate().take(MAX) { // Start another task to handle the connection - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { let mut stream = t!(stream); let mut buf = [0]; t!(stream.read(&mut buf)); @@ -412,7 +412,7 @@ mod tests { fn connect(i: usize, addr: SocketAddr) { if i == MAX { return } - let t = Thread::scoped(move|| { + let t = thread::spawn(move|| { let mut stream = t!(TcpStream::connect(&addr)); // Connect again before writing connect(i + 1, addr); @@ -428,10 +428,10 @@ mod tests { each_ip(&mut |addr| { let acceptor = t!(TcpListener::bind(&addr)); - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { for stream in acceptor.incoming().take(MAX) { // Start another task to handle the connection - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { let mut stream = t!(stream); let mut buf = [0]; t!(stream.read(&mut buf)); @@ -446,7 +446,7 @@ mod tests { fn connect(i: usize, addr: SocketAddr) { if i == MAX { return } - let t = Thread::scoped(move|| { + let t = thread::spawn(move|| { let mut stream = t!(TcpStream::connect(&addr)); connect(i + 1, addr); t!(stream.write(&[99])); @@ -467,7 +467,7 @@ mod tests { let listener = t!(TcpListener::bind(&addr)); let so_name = t!(listener.socket_addr()); assert_eq!(addr, so_name); - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { t!(listener.accept()); }); @@ -481,7 +481,7 @@ mod tests { each_ip(&mut |addr| { let (tx, rx) = channel(); let srv = t!(TcpListener::bind(&addr)); - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { let mut cl = t!(srv.accept()).0; cl.write(&[10]).unwrap(); let mut b = [0]; @@ -517,7 +517,7 @@ mod tests { each_ip(&mut |addr| { let acceptor = t!(TcpListener::bind(&addr)); - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { t!(TcpStream::connect(&addr)); }); @@ -532,7 +532,7 @@ mod tests { each_ip(&mut |addr| { let acceptor = t!(TcpListener::bind(&addr)); - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { let mut s = t!(TcpStream::connect(&addr)); let mut buf = [0, 0]; assert_eq!(s.read(&mut buf), Ok(1)); @@ -545,7 +545,7 @@ mod tests { let (tx1, rx1) = channel(); let (tx2, rx2) = channel(); - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { let mut s2 = s2; rx1.recv().unwrap(); t!(s2.write(&[1])); @@ -565,7 +565,7 @@ mod tests { let (tx1, rx) = channel(); let tx2 = tx1.clone(); - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { let mut s = t!(TcpStream::connect(&addr)); t!(s.write(&[1])); rx.recv().unwrap(); @@ -577,7 +577,7 @@ mod tests { let s2 = t!(s1.try_clone()); let (done, rx) = channel(); - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { let mut s2 = s2; let mut buf = [0, 0]; t!(s2.read(&mut buf)); @@ -597,7 +597,7 @@ mod tests { each_ip(&mut |addr| { let acceptor = t!(TcpListener::bind(&addr)); - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { let mut s = t!(TcpStream::connect(&addr)); let mut buf = [0, 1]; t!(s.read(&mut buf)); @@ -608,7 +608,7 @@ mod tests { let s2 = t!(s1.try_clone()); let (done, rx) = channel(); - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { let mut s2 = s2; t!(s2.write(&[1])); done.send(()).unwrap(); @@ -623,7 +623,7 @@ mod tests { fn shutdown_smoke() { each_ip(&mut |addr| { let a = t!(TcpListener::bind(&addr)); - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { let mut c = t!(a.accept()).0; let mut b = [0]; assert_eq!(c.read(&mut b), Ok(0)); @@ -644,7 +644,7 @@ mod tests { each_ip(&mut |addr| { let a = t!(TcpListener::bind(&addr)); let (tx, rx) = channel::<()>(); - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { let _s = t!(a.accept()); let _ = rx.recv(); }); @@ -682,7 +682,7 @@ mod tests { each_ip(&mut |addr| { let a = t!(TcpListener::bind(&addr)); let (tx1, rx) = channel::<()>(); - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { let _s = t!(a.accept()); let _ = rx.recv(); }); @@ -690,7 +690,7 @@ mod tests { let s = t!(TcpStream::connect(&addr)); let s2 = t!(s.try_clone()); let (tx, rx) = channel(); - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { let mut s2 = s2; assert_eq!(t!(s2.read(&mut [0])), 0); tx.send(()).unwrap(); @@ -713,7 +713,7 @@ mod tests { let (tx, rx) = channel(); let (txdone, rxdone) = channel(); let txdone2 = txdone.clone(); - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { let mut tcp = t!(TcpStream::connect(&addr)); rx.recv().unwrap(); t!(tcp.write(&[0])); @@ -724,7 +724,7 @@ mod tests { let tcp = t!(accept.accept()).0; let tcp2 = t!(tcp.try_clone()); let txdone3 = txdone.clone(); - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { let mut tcp2 = tcp2; t!(tcp2.read(&mut [0])); txdone3.send(()).unwrap(); @@ -732,7 +732,7 @@ mod tests { // Try to ensure that the reading clone is indeed reading for _ in 0..50 { - Thread::yield_now(); + thread::yield_now(); } // clone the handle again while it's reading, then let it finish the @@ -750,10 +750,10 @@ mod tests { let a = t!(TcpListener::bind(&addr)); let a2 = t!(a.try_clone()); - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { let _ = TcpStream::connect(&addr); }); - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { let _ = TcpStream::connect(&addr); }); @@ -771,17 +771,17 @@ mod tests { let (tx, rx) = channel(); let tx2 = tx.clone(); - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { tx.send(t!(a.accept())).unwrap(); }); - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { tx2.send(t!(a2.accept())).unwrap(); }); - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { let _ = TcpStream::connect(&addr); }); - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { let _ = TcpStream::connect(&addr); }); diff --git a/src/libstd/net/udp.rs b/src/libstd/net/udp.rs index d162a29790ea1..92f00599826dd 100644 --- a/src/libstd/net/udp.rs +++ b/src/libstd/net/udp.rs @@ -131,7 +131,7 @@ mod tests { use net::*; use net::test::{next_test_ip4, next_test_ip6}; use sync::mpsc::channel; - use thread::Thread; + use thread; fn each_ip(f: &mut FnMut(SocketAddr, SocketAddr)) { f(next_test_ip4(), next_test_ip4()); @@ -164,7 +164,7 @@ mod tests { let (tx1, rx1) = channel(); let (tx2, rx2) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let client = t!(UdpSocket::bind(&client_ip)); rx1.recv().unwrap(); t!(client.send_to(&[99], &server_ip)); @@ -196,7 +196,7 @@ mod tests { let sock1 = t!(UdpSocket::bind(&addr1)); let sock2 = t!(UdpSocket::bind(&addr2)); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut buf = [0, 0]; assert_eq!(sock2.recv_from(&mut buf), Ok((1, addr1))); assert_eq!(buf[0], 1); @@ -207,7 +207,7 @@ mod tests { let (tx1, rx1) = channel(); let (tx2, rx2) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { rx1.recv().unwrap(); t!(sock3.send_to(&[1], &addr2)); tx2.send(()).unwrap(); @@ -227,7 +227,7 @@ mod tests { let (tx1, rx) = channel(); let tx2 = tx1.clone(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { t!(sock2.send_to(&[1], &addr1)); rx.recv().unwrap(); t!(sock2.send_to(&[2], &addr1)); @@ -237,7 +237,7 @@ mod tests { let sock3 = t!(sock1.try_clone()); let (done, rx) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut buf = [0, 0]; t!(sock3.recv_from(&mut buf)); tx2.send(()).unwrap(); @@ -260,7 +260,7 @@ mod tests { let (tx, rx) = channel(); let (serv_tx, serv_rx) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut buf = [0, 1]; rx.recv().unwrap(); t!(sock2.recv_from(&mut buf)); @@ -271,7 +271,7 @@ mod tests { let (done, rx) = channel(); let tx2 = tx.clone(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { match sock3.send_to(&[1], &addr2) { Ok(..) => { let _ = tx2.send(()); } Err(..) => {} diff --git a/src/libstd/old_io/comm_adapters.rs b/src/libstd/old_io/comm_adapters.rs index d8f9b1bb3feae..a75686369ad3a 100644 --- a/src/libstd/old_io/comm_adapters.rs +++ b/src/libstd/old_io/comm_adapters.rs @@ -161,12 +161,12 @@ mod test { use sync::mpsc::channel; use super::*; use old_io; - use thread::Thread; + use thread; #[test] fn test_rx_reader() { let (tx, rx) = channel(); - Thread::spawn(move|| { + thread::spawn(move|| { tx.send(vec![1u8, 2u8]).unwrap(); tx.send(vec![]).unwrap(); tx.send(vec![3u8, 4u8]).unwrap(); @@ -208,7 +208,7 @@ mod test { #[test] fn test_rx_buffer() { let (tx, rx) = channel(); - Thread::spawn(move|| { + thread::spawn(move|| { tx.send(b"he".to_vec()).unwrap(); tx.send(b"llo wo".to_vec()).unwrap(); tx.send(b"".to_vec()).unwrap(); @@ -234,7 +234,7 @@ mod test { writer.write_be_u32(42).unwrap(); let wanted = vec![0u8, 0u8, 0u8, 42u8]; - let got = match Thread::scoped(move|| { rx.recv().unwrap() }).join() { + let got = match thread::spawn(move|| { rx.recv().unwrap() }).join() { Ok(got) => got, Err(_) => panic!(), }; diff --git a/src/libstd/old_io/mod.rs b/src/libstd/old_io/mod.rs index 94f4af8e558ad..deed210a1749c 100644 --- a/src/libstd/old_io/mod.rs +++ b/src/libstd/old_io/mod.rs @@ -124,7 +124,7 @@ //! # #![allow(dead_code)] //! use std::old_io::{TcpListener, TcpStream}; //! use std::old_io::{Acceptor, Listener}; -//! use std::thread::Thread; +//! use std::thread; //! //! let listener = TcpListener::bind("127.0.0.1:80"); //! @@ -140,7 +140,7 @@ //! match stream { //! Err(e) => { /* connection failed */ } //! Ok(stream) => { -//! Thread::spawn(move|| { +//! thread::spawn(move|| { //! // connection succeeded //! handle_client(stream) //! }); diff --git a/src/libstd/old_io/net/pipe.rs b/src/libstd/old_io/net/pipe.rs index 8c4a10a55d489..8e0126d5ec8e1 100644 --- a/src/libstd/old_io/net/pipe.rs +++ b/src/libstd/old_io/net/pipe.rs @@ -282,7 +282,7 @@ mod tests { use old_io::test::*; use super::*; use sync::mpsc::channel; - use thread::Thread; + use thread; use time::Duration; pub fn smalltest(server: F, client: G) @@ -294,7 +294,7 @@ mod tests { let mut acceptor = UnixListener::bind(&path1).listen(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { match UnixStream::connect(&path2) { Ok(c) => client(c), Err(e) => panic!("failed connect: {}", e), @@ -389,7 +389,7 @@ mod tests { Err(e) => panic!("failed listen: {}", e), }; - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { for _ in 0u..times { let mut stream = UnixStream::connect(&path2); match stream.write(&[100]) { @@ -423,7 +423,7 @@ mod tests { let addr = next_test_unix(); let mut acceptor = UnixListener::bind(&addr).listen(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut s = UnixStream::connect(&addr); let mut buf = [0, 0]; debug!("client reading"); @@ -439,7 +439,7 @@ mod tests { let (tx1, rx1) = channel(); let (tx2, rx2) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut s2 = s2; rx1.recv().unwrap(); debug!("writer writing"); @@ -462,7 +462,7 @@ mod tests { let (tx1, rx) = channel(); let tx2 = tx1.clone(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut s = UnixStream::connect(&addr); s.write(&[1]).unwrap(); rx.recv().unwrap(); @@ -474,7 +474,7 @@ mod tests { let s2 = s1.clone(); let (done, rx) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut s2 = s2; let mut buf = [0, 0]; s2.read(&mut buf).unwrap(); @@ -493,7 +493,7 @@ mod tests { let addr = next_test_unix(); let mut acceptor = UnixListener::bind(&addr).listen(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut s = UnixStream::connect(&addr); let buf = &mut [0, 1]; s.read(buf).unwrap(); @@ -504,7 +504,7 @@ mod tests { let s2 = s1.clone(); let (tx, rx) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut s2 = s2; s2.write(&[1]).unwrap(); tx.send(()).unwrap(); @@ -551,7 +551,7 @@ mod tests { // continue to receive any pending connections. let (tx, rx) = channel(); let addr2 = addr.clone(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { tx.send(UnixStream::connect(&addr2).unwrap()).unwrap(); }); let l = rx.recv().unwrap(); @@ -561,7 +561,7 @@ mod tests { Err(ref e) if e.kind == TimedOut => {} Err(e) => panic!("error: {}", e), } - ::thread::Thread::yield_now(); + ::thread::yield_now(); if i == 1000 { panic!("should have a pending connection") } } drop(l); @@ -569,7 +569,7 @@ mod tests { // Unset the timeout and make sure that this always blocks. a.set_timeout(None); let addr2 = addr.clone(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { drop(UnixStream::connect(&addr2).unwrap()); }); a.accept().unwrap(); @@ -607,7 +607,7 @@ mod tests { let addr = next_test_unix(); let a = UnixListener::bind(&addr).listen().unwrap(); let (_tx, rx) = channel::<()>(); - Thread::spawn(move|| { + thread::spawn(move|| { let mut a = a; let _s = a.accept().unwrap(); let _ = rx.recv(); @@ -644,7 +644,7 @@ mod tests { let addr = next_test_unix(); let a = UnixListener::bind(&addr).listen().unwrap(); let (_tx, rx) = channel::<()>(); - Thread::spawn(move|| { + thread::spawn(move|| { let mut a = a; let _s = a.accept().unwrap(); let _ = rx.recv(); @@ -653,7 +653,7 @@ mod tests { let mut s = UnixStream::connect(&addr).unwrap(); let s2 = s.clone(); let (tx, rx) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut s2 = s2; assert!(s2.read(&mut [0]).is_err()); tx.send(()).unwrap(); @@ -670,7 +670,7 @@ mod tests { let addr = next_test_unix(); let mut a = UnixListener::bind(&addr).listen().unwrap(); let (tx, rx) = channel::<()>(); - Thread::spawn(move|| { + thread::spawn(move|| { let mut s = UnixStream::connect(&addr).unwrap(); rx.recv().unwrap(); assert!(s.write(&[0]).is_ok()); @@ -708,7 +708,7 @@ mod tests { let addr = next_test_unix(); let mut a = UnixListener::bind(&addr).listen().unwrap(); let (tx, rx) = channel::<()>(); - Thread::spawn(move|| { + thread::spawn(move|| { let mut s = UnixStream::connect(&addr).unwrap(); rx.recv().unwrap(); let mut amt = 0; @@ -737,7 +737,7 @@ mod tests { let addr = next_test_unix(); let mut a = UnixListener::bind(&addr).listen().unwrap(); let (tx, rx) = channel::<()>(); - Thread::spawn(move|| { + thread::spawn(move|| { let mut s = UnixStream::connect(&addr).unwrap(); rx.recv().unwrap(); assert!(s.write(&[0]).is_ok()); @@ -764,7 +764,7 @@ mod tests { let addr = next_test_unix(); let mut a = UnixListener::bind(&addr).listen().unwrap(); let (tx, rx) = channel::<()>(); - Thread::spawn(move|| { + thread::spawn(move|| { let mut s = UnixStream::connect(&addr).unwrap(); rx.recv().unwrap(); assert!(s.write(&[0]).is_ok()); @@ -774,7 +774,7 @@ mod tests { let mut s = a.accept().unwrap(); let s2 = s.clone(); let (tx2, rx2) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut s2 = s2; assert!(s2.read(&mut [0]).is_ok()); tx2.send(()).unwrap(); @@ -796,10 +796,10 @@ mod tests { let mut a2 = a.clone(); let addr2 = addr.clone(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let _ = UnixStream::connect(&addr2); }); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let _ = UnixStream::connect(&addr); }); @@ -819,20 +819,20 @@ mod tests { let (tx, rx) = channel(); let tx2 = tx.clone(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut a = a; tx.send(a.accept()).unwrap() }); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut a = a2; tx2.send(a.accept()).unwrap() }); let addr2 = addr.clone(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let _ = UnixStream::connect(&addr2); }); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let _ = UnixStream::connect(&addr); }); @@ -858,7 +858,7 @@ mod tests { let mut a2 = a.clone(); let (tx, rx) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut a = a; tx.send(a.accept()).unwrap(); }); diff --git a/src/libstd/old_io/net/tcp.rs b/src/libstd/old_io/net/tcp.rs index ebf7f6cc0f2a9..5ab0880080bc2 100644 --- a/src/libstd/old_io/net/tcp.rs +++ b/src/libstd/old_io/net/tcp.rs @@ -137,12 +137,12 @@ impl TcpStream { /// use std::old_io::timer; /// use std::old_io::TcpStream; /// use std::time::Duration; - /// use std::thread::Thread; + /// use std::thread; /// /// let mut stream = TcpStream::connect("127.0.0.1:34254").unwrap(); /// let stream2 = stream.clone(); /// - /// let _t = Thread::spawn(move|| { + /// let _t = thread::spawn(move|| { /// // close this stream after one second /// timer::sleep(Duration::seconds(1)); /// let mut stream = stream2; @@ -282,7 +282,7 @@ impl sys_common::AsInner for TcpStream { /// # fn foo() { /// use std::old_io::{TcpListener, TcpStream}; /// use std::old_io::{Acceptor, Listener}; -/// use std::thread::Thread; +/// use std::thread; /// /// let listener = TcpListener::bind("127.0.0.1:80").unwrap(); /// @@ -298,7 +298,7 @@ impl sys_common::AsInner for TcpStream { /// match stream { /// Err(e) => { /* connection failed */ } /// Ok(stream) => { -/// Thread::spawn(move|| { +/// thread::spawn(move|| { /// // connection succeeded /// handle_client(stream) /// }); @@ -421,12 +421,12 @@ impl TcpAcceptor { /// /// ``` /// use std::old_io::{TcpListener, Listener, Acceptor, EndOfFile}; - /// use std::thread::Thread; + /// use std::thread; /// /// let mut a = TcpListener::bind("127.0.0.1:8482").listen().unwrap(); /// let a2 = a.clone(); /// - /// let _t = Thread::spawn(move|| { + /// let _t = thread::spawn(move|| { /// let mut a2 = a2; /// for socket in a2.incoming() { /// match socket { @@ -487,7 +487,7 @@ mod test { use prelude::v1::*; use sync::mpsc::channel; - use thread::Thread; + use thread; use old_io::net::tcp::*; use old_io::net::ip::*; use old_io::test::*; @@ -520,7 +520,7 @@ mod test { let listener = TcpListener::bind(socket_addr); let mut acceptor = listener.listen(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut stream = TcpStream::connect(("localhost", socket_addr.port)); stream.write(&[144]).unwrap(); }); @@ -536,7 +536,7 @@ mod test { let addr = next_test_ip4(); let mut acceptor = TcpListener::bind(addr).listen(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut stream = TcpStream::connect(("localhost", addr.port)); stream.write(&[64]).unwrap(); }); @@ -552,7 +552,7 @@ mod test { let addr = next_test_ip4(); let mut acceptor = TcpListener::bind(addr).listen(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut stream = TcpStream::connect(("127.0.0.1", addr.port)); stream.write(&[44]).unwrap(); }); @@ -568,7 +568,7 @@ mod test { let addr = next_test_ip6(); let mut acceptor = TcpListener::bind(addr).listen(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut stream = TcpStream::connect(("::1", addr.port)); stream.write(&[66]).unwrap(); }); @@ -584,7 +584,7 @@ mod test { let addr = next_test_ip4(); let mut acceptor = TcpListener::bind(addr).listen(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut stream = TcpStream::connect(addr); stream.write(&[99]).unwrap(); }); @@ -600,7 +600,7 @@ mod test { let addr = next_test_ip6(); let mut acceptor = TcpListener::bind(addr).listen(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut stream = TcpStream::connect(addr); stream.write(&[99]).unwrap(); }); @@ -616,7 +616,7 @@ mod test { let addr = next_test_ip4(); let mut acceptor = TcpListener::bind(addr).listen(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let _stream = TcpStream::connect(addr); // Close }); @@ -632,7 +632,7 @@ mod test { let addr = next_test_ip6(); let mut acceptor = TcpListener::bind(addr).listen(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let _stream = TcpStream::connect(addr); // Close }); @@ -648,7 +648,7 @@ mod test { let addr = next_test_ip4(); let mut acceptor = TcpListener::bind(addr).listen(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let _stream = TcpStream::connect(addr); // Close }); @@ -672,7 +672,7 @@ mod test { let addr = next_test_ip6(); let mut acceptor = TcpListener::bind(addr).listen(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let _stream = TcpStream::connect(addr); // Close }); @@ -697,7 +697,7 @@ mod test { let mut acceptor = TcpListener::bind(addr).listen(); let (tx, rx) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { drop(TcpStream::connect(addr)); tx.send(()).unwrap(); }); @@ -722,7 +722,7 @@ mod test { let mut acceptor = TcpListener::bind(addr).listen(); let (tx, rx) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { drop(TcpStream::connect(addr)); tx.send(()).unwrap(); }); @@ -747,7 +747,7 @@ mod test { let max = 10u; let mut acceptor = TcpListener::bind(addr).listen(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { for _ in 0..max { let mut stream = TcpStream::connect(addr); stream.write(&[99]).unwrap(); @@ -767,7 +767,7 @@ mod test { let max = 10u; let mut acceptor = TcpListener::bind(addr).listen(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { for _ in 0..max { let mut stream = TcpStream::connect(addr); stream.write(&[99]).unwrap(); @@ -787,11 +787,11 @@ mod test { static MAX: int = 10; let acceptor = TcpListener::bind(addr).listen(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut acceptor = acceptor; for (i, stream) in acceptor.incoming().enumerate().take(MAX as uint) { // Start another task to handle the connection - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut stream = stream; let mut buf = [0]; stream.read(&mut buf).unwrap(); @@ -806,7 +806,7 @@ mod test { fn connect(i: int, addr: SocketAddr) { if i == MAX { return } - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { debug!("connecting"); let mut stream = TcpStream::connect(addr); // Connect again before writing @@ -823,11 +823,11 @@ mod test { static MAX: int = 10; let acceptor = TcpListener::bind(addr).listen(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut acceptor = acceptor; for (i, stream) in acceptor.incoming().enumerate().take(MAX as uint) { // Start another task to handle the connection - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut stream = stream; let mut buf = [0]; stream.read(&mut buf).unwrap(); @@ -842,7 +842,7 @@ mod test { fn connect(i: int, addr: SocketAddr) { if i == MAX { return } - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { debug!("connecting"); let mut stream = TcpStream::connect(addr); // Connect again before writing @@ -859,11 +859,11 @@ mod test { let addr = next_test_ip4(); let acceptor = TcpListener::bind(addr).listen(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut acceptor = acceptor; for stream in acceptor.incoming().take(MAX as uint) { // Start another task to handle the connection - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut stream = stream; let mut buf = [0]; stream.read(&mut buf).unwrap(); @@ -878,7 +878,7 @@ mod test { fn connect(i: int, addr: SocketAddr) { if i == MAX { return } - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { debug!("connecting"); let mut stream = TcpStream::connect(addr); // Connect again before writing @@ -895,11 +895,11 @@ mod test { let addr = next_test_ip6(); let acceptor = TcpListener::bind(addr).listen(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut acceptor = acceptor; for stream in acceptor.incoming().take(MAX as uint) { // Start another task to handle the connection - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut stream = stream; let mut buf = [0]; stream.read(&mut buf).unwrap(); @@ -914,7 +914,7 @@ mod test { fn connect(i: int, addr: SocketAddr) { if i == MAX { return } - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { debug!("connecting"); let mut stream = TcpStream::connect(addr); // Connect again before writing @@ -937,7 +937,7 @@ mod test { pub fn peer_name(addr: SocketAddr) { let acceptor = TcpListener::bind(addr).listen(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut acceptor = acceptor; acceptor.accept().unwrap(); }); @@ -972,7 +972,7 @@ mod test { fn partial_read() { let addr = next_test_ip4(); let (tx, rx) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut srv = TcpListener::bind(addr).listen().unwrap(); tx.send(()).unwrap(); let mut cl = srv.accept().unwrap(); @@ -1009,7 +1009,7 @@ mod test { let addr = next_test_ip4(); let (tx, rx) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { rx.recv().unwrap(); let _stream = TcpStream::connect(addr).unwrap(); // Close @@ -1034,7 +1034,7 @@ mod test { let addr = next_test_ip4(); let mut acceptor = TcpListener::bind(addr).listen(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut s = TcpStream::connect(addr); let mut buf = [0, 0]; assert_eq!(s.read(&mut buf), Ok(1)); @@ -1047,7 +1047,7 @@ mod test { let (tx1, rx1) = channel(); let (tx2, rx2) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut s2 = s2; rx1.recv().unwrap(); s2.write(&[1]).unwrap(); @@ -1066,7 +1066,7 @@ mod test { let (tx1, rx) = channel(); let tx2 = tx1.clone(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut s = TcpStream::connect(addr); s.write(&[1]).unwrap(); rx.recv().unwrap(); @@ -1078,7 +1078,7 @@ mod test { let s2 = s1.clone(); let (done, rx) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut s2 = s2; let mut buf = [0, 0]; s2.read(&mut buf).unwrap(); @@ -1097,7 +1097,7 @@ mod test { let addr = next_test_ip4(); let mut acceptor = TcpListener::bind(addr).listen(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut s = TcpStream::connect(addr); let mut buf = [0, 1]; s.read(&mut buf).unwrap(); @@ -1108,7 +1108,7 @@ mod test { let s2 = s1.clone(); let (done, rx) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut s2 = s2; s2.write(&[1]).unwrap(); done.send(()).unwrap(); @@ -1122,7 +1122,7 @@ mod test { fn shutdown_smoke() { let addr = next_test_ip4(); let a = TcpListener::bind(addr).unwrap().listen(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut a = a; let mut c = a.accept().unwrap(); assert_eq!(c.read_to_end(), Ok(vec!())); @@ -1156,7 +1156,7 @@ mod test { // flakiness. if !cfg!(target_os = "freebsd") { let (tx, rx) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { tx.send(TcpStream::connect(addr).unwrap()).unwrap(); }); let _l = rx.recv().unwrap(); @@ -1166,14 +1166,14 @@ mod test { Err(ref e) if e.kind == TimedOut => {} Err(e) => panic!("error: {}", e), } - ::thread::Thread::yield_now(); + ::thread::yield_now(); if i == 1000 { panic!("should have a pending connection") } } } // Unset the timeout and make sure that this always blocks. a.set_timeout(None); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { drop(TcpStream::connect(addr).unwrap()); }); a.accept().unwrap(); @@ -1184,7 +1184,7 @@ mod test { let addr = next_test_ip4(); let a = TcpListener::bind(addr).listen().unwrap(); let (_tx, rx) = channel::<()>(); - Thread::spawn(move|| { + thread::spawn(move|| { let mut a = a; let _s = a.accept().unwrap(); let _ = rx.recv().unwrap(); @@ -1221,7 +1221,7 @@ mod test { let addr = next_test_ip4(); let a = TcpListener::bind(addr).listen().unwrap(); let (_tx, rx) = channel::<()>(); - Thread::spawn(move|| { + thread::spawn(move|| { let mut a = a; let _s = a.accept().unwrap(); let _ = rx.recv().unwrap(); @@ -1230,7 +1230,7 @@ mod test { let mut s = TcpStream::connect(addr).unwrap(); let s2 = s.clone(); let (tx, rx) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut s2 = s2; assert!(s2.read(&mut [0]).is_err()); tx.send(()).unwrap(); @@ -1247,7 +1247,7 @@ mod test { let addr = next_test_ip6(); let mut a = TcpListener::bind(addr).listen().unwrap(); let (tx, rx) = channel::<()>(); - Thread::spawn(move|| { + thread::spawn(move|| { let mut s = TcpStream::connect(addr).unwrap(); rx.recv().unwrap(); assert!(s.write(&[0]).is_ok()); @@ -1280,7 +1280,7 @@ mod test { let addr = next_test_ip6(); let mut a = TcpListener::bind(addr).listen().unwrap(); let (tx, rx) = channel::<()>(); - Thread::spawn(move|| { + thread::spawn(move|| { let mut s = TcpStream::connect(addr).unwrap(); rx.recv().unwrap(); let mut amt = 0; @@ -1309,7 +1309,7 @@ mod test { let addr = next_test_ip6(); let mut a = TcpListener::bind(addr).listen().unwrap(); let (tx, rx) = channel::<()>(); - Thread::spawn(move|| { + thread::spawn(move|| { let mut s = TcpStream::connect(addr).unwrap(); rx.recv().unwrap(); assert!(s.write(&[0]).is_ok()); @@ -1337,7 +1337,7 @@ mod test { let addr = next_test_ip6(); let mut a = TcpListener::bind(addr).listen().unwrap(); let (tx, rx) = channel::<()>(); - Thread::spawn(move|| { + thread::spawn(move|| { let mut s = TcpStream::connect(addr).unwrap(); rx.recv().unwrap(); assert_eq!(s.write(&[0]), Ok(())); @@ -1347,7 +1347,7 @@ mod test { let mut s = a.accept().unwrap(); let s2 = s.clone(); let (tx2, rx2) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut s2 = s2; assert_eq!(s2.read(&mut [0]), Ok(1)); tx2.send(()).unwrap(); @@ -1370,7 +1370,7 @@ mod test { let (tx, rx) = channel(); let (txdone, rxdone) = channel(); let txdone2 = txdone.clone(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut tcp = TcpStream::connect(addr).unwrap(); rx.recv().unwrap(); tcp.write_u8(0).unwrap(); @@ -1381,7 +1381,7 @@ mod test { let tcp = accept.accept().unwrap(); let tcp2 = tcp.clone(); let txdone3 = txdone.clone(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut tcp2 = tcp2; tcp2.read_u8().unwrap(); txdone3.send(()).unwrap(); @@ -1389,7 +1389,7 @@ mod test { // Try to ensure that the reading clone is indeed reading for _ in 0..50 { - ::thread::Thread::yield_now(); + ::thread::yield_now(); } // clone the handle again while it's reading, then let it finish the @@ -1407,10 +1407,10 @@ mod test { let mut a = l.listen().unwrap(); let mut a2 = a.clone(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let _ = TcpStream::connect(addr); }); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let _ = TcpStream::connect(addr); }); @@ -1428,19 +1428,19 @@ mod test { let (tx, rx) = channel(); let tx2 = tx.clone(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut a = a; tx.send(a.accept()).unwrap(); }); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut a = a2; tx2.send(a.accept()).unwrap(); }); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let _ = TcpStream::connect(addr); }); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let _ = TcpStream::connect(addr); }); @@ -1466,7 +1466,7 @@ mod test { let mut a2 = a.clone(); let (tx, rx) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut a = a; tx.send(a.accept()).unwrap(); }); diff --git a/src/libstd/old_io/net/udp.rs b/src/libstd/old_io/net/udp.rs index 8dc19047de08e..7171198e7a4aa 100644 --- a/src/libstd/old_io/net/udp.rs +++ b/src/libstd/old_io/net/udp.rs @@ -186,7 +186,7 @@ mod test { use old_io::test::*; use old_io::{IoError, TimedOut, PermissionDenied, ShortWrite}; use super::*; - use thread::Thread; + use thread; // FIXME #11530 this fails on android because tests are run as root #[cfg_attr(any(windows, target_os = "android"), ignore)] @@ -206,7 +206,7 @@ mod test { let (tx1, rx1) = channel(); let (tx2, rx2) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { match UdpSocket::bind(client_ip) { Ok(ref mut client) => { rx1.recv().unwrap(); @@ -241,7 +241,7 @@ mod test { let client_ip = next_test_ip6(); let (tx, rx) = channel::<()>(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { match UdpSocket::bind(client_ip) { Ok(ref mut client) => { rx.recv().unwrap(); @@ -298,7 +298,7 @@ mod test { let mut sock1 = UdpSocket::bind(addr1).unwrap(); let sock2 = UdpSocket::bind(addr2).unwrap(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut sock2 = sock2; let mut buf = [0, 0]; assert_eq!(sock2.recv_from(&mut buf), Ok((1, addr1))); @@ -310,7 +310,7 @@ mod test { let (tx1, rx1) = channel(); let (tx2, rx2) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut sock3 = sock3; rx1.recv().unwrap(); sock3.send_to(&[1], addr2).unwrap(); @@ -331,7 +331,7 @@ mod test { let (tx1, rx) = channel(); let tx2 = tx1.clone(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut sock2 = sock2; sock2.send_to(&[1], addr1).unwrap(); rx.recv().unwrap(); @@ -342,7 +342,7 @@ mod test { let sock3 = sock1.clone(); let (done, rx) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut sock3 = sock3; let mut buf = [0, 0]; sock3.recv_from(&mut buf).unwrap(); @@ -366,7 +366,7 @@ mod test { let (tx, rx) = channel(); let (serv_tx, serv_rx) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut sock2 = sock2; let mut buf = [0, 1]; @@ -382,7 +382,7 @@ mod test { let (done, rx) = channel(); let tx2 = tx.clone(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut sock3 = sock3; match sock3.send_to(&[1], addr2) { Ok(..) => { let _ = tx2.send(()); } @@ -410,7 +410,7 @@ mod test { let (tx, rx) = channel(); let (tx2, rx2) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut a = a2; assert_eq!(a.recv_from(&mut [0]), Ok((1, addr1))); assert_eq!(a.send_to(&[0], addr1), Ok(())); diff --git a/src/libstd/old_io/pipe.rs b/src/libstd/old_io/pipe.rs index 5843b1ba1b13f..b7b626db034e1 100644 --- a/src/libstd/old_io/pipe.rs +++ b/src/libstd/old_io/pipe.rs @@ -115,7 +115,7 @@ mod test { use prelude::v1::*; use sync::mpsc::channel; - use thread::Thread; + use thread; #[test] fn partial_read() { @@ -126,7 +126,7 @@ mod test { let out = PipeStream::open(writer); let mut input = PipeStream::open(reader); let (tx, rx) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut out = out; out.write(&[10]).unwrap(); rx.recv().unwrap(); // don't close the pipe until the other read has finished diff --git a/src/libstd/old_io/process.rs b/src/libstd/old_io/process.rs index 195d33c41a68e..8ed0946d857b7 100644 --- a/src/libstd/old_io/process.rs +++ b/src/libstd/old_io/process.rs @@ -30,7 +30,7 @@ use sync::mpsc::{channel, Receiver}; use sys::fs::FileDesc; use sys::process::Process as ProcessImp; use sys; -use thread::Thread; +use thread; #[cfg(windows)] use hash; #[cfg(windows)] use str; @@ -703,7 +703,7 @@ impl Process { let (tx, rx) = channel(); match stream { Some(stream) => { - Thread::spawn(move || { + thread::spawn(move || { let mut stream = stream; tx.send(stream.read_to_end()).unwrap(); }); @@ -764,7 +764,7 @@ mod tests { use super::{CreatePipe}; use super::{InheritFd, Process, PleaseExitSignal, Command, ProcessOutput}; use sync::mpsc::channel; - use thread::Thread; + use thread; use time::Duration; // FIXME(#10380) these tests should not all be ignored on android. @@ -1169,14 +1169,14 @@ mod tests { fn wait_timeout2() { let (tx, rx) = channel(); let tx2 = tx.clone(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut p = sleeper(); p.set_timeout(Some(10)); assert_eq!(p.wait().err().unwrap().kind, TimedOut); p.signal_kill().unwrap(); tx.send(()).unwrap(); }); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut p = sleeper(); p.set_timeout(Some(10)); assert_eq!(p.wait().err().unwrap().kind, TimedOut); diff --git a/src/libstd/old_io/stdio.rs b/src/libstd/old_io/stdio.rs index 70cce1f7e769e..e3d0232684fcc 100644 --- a/src/libstd/old_io/stdio.rs +++ b/src/libstd/old_io/stdio.rs @@ -530,7 +530,7 @@ mod tests { use super::*; use sync::mpsc::channel; - use thread::Thread; + use thread; #[test] fn smoke() { @@ -546,7 +546,7 @@ mod tests { let (tx, rx) = channel(); let (mut r, w) = (ChanReader::new(rx), ChanWriter::new(tx)); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { set_stdout(box w); println!("hello!"); }); @@ -559,7 +559,7 @@ mod tests { let (tx, rx) = channel(); let (mut r, w) = (ChanReader::new(rx), ChanWriter::new(tx)); - let _t = Thread::spawn(move || -> () { + let _t = thread::spawn(move || -> () { set_stderr(box w); panic!("my special message"); }); diff --git a/src/libstd/old_io/timer.rs b/src/libstd/old_io/timer.rs index 35f0bcb21d94b..8b84e27eae1ba 100644 --- a/src/libstd/old_io/timer.rs +++ b/src/libstd/old_io/timer.rs @@ -224,13 +224,13 @@ fn in_ms_u64(d: Duration) -> u64 { #[cfg(test)] mod test { use super::Timer; - use thread::Thread; + use thread; use time::Duration; #[test] fn test_timer_send() { let mut timer = Timer::new().unwrap(); - Thread::spawn(move || timer.sleep(Duration::milliseconds(1))); + thread::spawn(move || timer.sleep(Duration::milliseconds(1))); } #[test] @@ -360,7 +360,7 @@ mod test { let mut timer = Timer::new().unwrap(); let timer_rx = timer.periodic(Duration::milliseconds(1000)); - Thread::spawn(move|| { + thread::spawn(move|| { let _ = timer_rx.recv(); }); @@ -374,7 +374,7 @@ mod test { let mut timer = Timer::new().unwrap(); let timer_rx = timer.periodic(Duration::milliseconds(1000)); - Thread::spawn(move|| { + thread::spawn(move|| { let _ = timer_rx.recv(); }); @@ -387,7 +387,7 @@ mod test { let mut timer = Timer::new().unwrap(); let timer_rx = timer.periodic(Duration::milliseconds(1000)); - Thread::spawn(move|| { + thread::spawn(move|| { let _ = timer_rx.recv(); }); diff --git a/src/libstd/old_path/posix.rs b/src/libstd/old_path/posix.rs index 6bf2a30b7b184..9bbce1934b08c 100644 --- a/src/libstd/old_path/posix.rs +++ b/src/libstd/old_path/posix.rs @@ -518,18 +518,18 @@ mod tests { #[test] fn test_null_byte() { - use thread::Thread; - let result = Thread::scoped(move|| { + use thread; + let result = thread::spawn(move|| { Path::new(b"foo/bar\0") }).join(); assert!(result.is_err()); - let result = Thread::scoped(move|| { + let result = thread::spawn(move|| { Path::new("test").set_filename(b"f\0o") }).join(); assert!(result.is_err()); - let result = Thread::scoped(move|| { + let result = thread::spawn(move|| { Path::new("test").push(b"f\0o"); }).join(); assert!(result.is_err()); diff --git a/src/libstd/old_path/windows.rs b/src/libstd/old_path/windows.rs index 54c070e1b7db8..8362e9a9530b9 100644 --- a/src/libstd/old_path/windows.rs +++ b/src/libstd/old_path/windows.rs @@ -1305,18 +1305,18 @@ mod tests { #[test] fn test_null_byte() { - use thread::Thread; - let result = Thread::scoped(move|| { + use thread; + let result = thread::spawn(move|| { Path::new(b"foo/bar\0") }).join(); assert!(result.is_err()); - let result = Thread::scoped(move|| { + let result = thread::spawn(move|| { Path::new("test").set_filename(b"f\0o") }).join(); assert!(result.is_err()); - let result = Thread::scoped(move || { + let result = thread::spawn(move || { Path::new("test").push(b"f\0o"); }).join(); assert!(result.is_err()); diff --git a/src/libstd/panicking.rs b/src/libstd/panicking.rs index e485c6a63c6f1..35221a7e647cc 100644 --- a/src/libstd/panicking.rs +++ b/src/libstd/panicking.rs @@ -17,7 +17,7 @@ use cell::RefCell; use old_io::IoResult; use rt::{backtrace, unwind}; use rt::util::{Stderr, Stdio}; -use thread::Thread; +use thread; // Defined in this module instead of old_io::stdio so that the unwinding thread_local! { @@ -42,7 +42,7 @@ pub fn on_panic(obj: &(Any+Send), file: &'static str, line: uint) { } }; let mut err = Stderr; - let thread = Thread::current(); + let thread = thread::current(); let name = thread.name().unwrap_or(""); let prev = LOCAL_STDERR.with(|s| s.borrow_mut().take()); match prev { diff --git a/src/libstd/process.rs b/src/libstd/process.rs index d2b98ec89390b..4843138a104bd 100644 --- a/src/libstd/process.rs +++ b/src/libstd/process.rs @@ -27,7 +27,7 @@ use sys::process2::Process as ProcessImp; use sys::process2::Command as CommandImp; use sys::process2::ExitStatus as ExitStatusImp; use sys_common::{AsInner, AsInnerMut}; -use thread::Thread; +use thread; /// Representation of a running or exited child process. /// @@ -462,7 +462,7 @@ impl Child { let (tx, rx) = channel(); match stream { Some(stream) => { - Thread::spawn(move || { + thread::spawn(move || { let mut stream = stream; let mut ret = Vec::new(); let res = stream.read_to_end(&mut ret); @@ -499,7 +499,7 @@ mod tests { use str; use super::{Child, Command, Output, ExitStatus, Stdio}; use sync::mpsc::channel; - use thread::Thread; + use thread; use time::Duration; // FIXME(#10380) these tests should not all be ignored on android. diff --git a/src/libstd/rand/os.rs b/src/libstd/rand/os.rs index 535af08c96c70..0feacf5581c97 100644 --- a/src/libstd/rand/os.rs +++ b/src/libstd/rand/os.rs @@ -360,7 +360,7 @@ mod test { use sync::mpsc::channel; use rand::Rng; use super::OsRng; - use thread::Thread; + use thread; #[test] fn test_os_rng() { @@ -381,23 +381,23 @@ mod test { let (tx, rx) = channel(); txs.push(tx); - Thread::spawn(move|| { + thread::spawn(move|| { // wait until all the tasks are ready to go. rx.recv().unwrap(); // deschedule to attempt to interleave things as much // as possible (XXX: is this a good test?) let mut r = OsRng::new().unwrap(); - Thread::yield_now(); + thread::yield_now(); let mut v = [0u8; 1000]; for _ in 0u..100 { r.next_u32(); - Thread::yield_now(); + thread::yield_now(); r.next_u64(); - Thread::yield_now(); + thread::yield_now(); r.fill_bytes(&mut v); - Thread::yield_now(); + thread::yield_now(); } }); } diff --git a/src/libstd/rt/util.rs b/src/libstd/rt/util.rs index bb57d19ed2666..4868da5e69f2e 100644 --- a/src/libstd/rt/util.rs +++ b/src/libstd/rt/util.rs @@ -149,7 +149,7 @@ pub fn abort(args: fmt::Arguments) -> ! { } pub unsafe fn report_overflow() { - use thread::Thread; + use thread; // See the message below for why this is not emitted to the // ^ Where did the message below go? @@ -159,5 +159,5 @@ pub unsafe fn report_overflow() { // and the FFI call needs 2MB of stack when we just ran out. rterrln!("\nthread '{}' has overflowed its stack", - Thread::current().name().unwrap_or("")); + thread::current().name().unwrap_or("")); } diff --git a/src/libstd/sync/barrier.rs b/src/libstd/sync/barrier.rs index cca376f7b6d05..fc781eb4bece4 100644 --- a/src/libstd/sync/barrier.rs +++ b/src/libstd/sync/barrier.rs @@ -15,14 +15,14 @@ use sync::{Mutex, Condvar}; /// /// ```rust /// use std::sync::{Arc, Barrier}; -/// use std::thread::Thread; +/// use std::thread; /// /// let barrier = Arc::new(Barrier::new(10)); /// for _ in 0u..10 { /// let c = barrier.clone(); /// // The same messages will be printed together. /// // You will NOT see any interleaving. -/// Thread::spawn(move|| { +/// thread::spawn(move|| { /// println!("before wait"); /// c.wait(); /// println!("after wait"); @@ -111,7 +111,7 @@ mod tests { use sync::{Arc, Barrier}; use sync::mpsc::{channel, TryRecvError}; - use thread::Thread; + use thread; #[test] fn test_barrier() { @@ -123,7 +123,7 @@ mod tests { for _ in 0u..N - 1 { let c = barrier.clone(); let tx = tx.clone(); - Thread::spawn(move|| { + thread::spawn(move|| { tx.send(c.wait().is_leader()).unwrap(); }); } diff --git a/src/libstd/sync/condvar.rs b/src/libstd/sync/condvar.rs index d4d722cab3d92..52561d482c39d 100644 --- a/src/libstd/sync/condvar.rs +++ b/src/libstd/sync/condvar.rs @@ -38,13 +38,13 @@ use sync::{mutex, MutexGuard, PoisonError}; /// /// ``` /// use std::sync::{Arc, Mutex, Condvar}; -/// use std::thread::Thread; +/// use std::thread; /// /// let pair = Arc::new((Mutex::new(false), Condvar::new())); /// let pair2 = pair.clone(); /// /// // Inside of our lock, spawn a new thread, and then wait for it to start -/// Thread::spawn(move|| { +/// thread::spawn(move|| { /// let &(ref lock, ref cvar) = &*pair2; /// let mut started = lock.lock().unwrap(); /// *started = true; @@ -353,7 +353,7 @@ mod tests { use sync::mpsc::channel; use sync::{StaticMutex, MUTEX_INIT, Condvar, Mutex, Arc}; use sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering}; - use thread::Thread; + use thread; use time::Duration; #[test] @@ -377,7 +377,7 @@ mod tests { static M: StaticMutex = MUTEX_INIT; let g = M.lock().unwrap(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let _g = M.lock().unwrap(); C.notify_one(); }); @@ -395,7 +395,7 @@ mod tests { for _ in 0..N { let data = data.clone(); let tx = tx.clone(); - Thread::spawn(move|| { + thread::spawn(move|| { let &(ref lock, ref cond) = &*data; let mut cnt = lock.lock().unwrap(); *cnt += 1; @@ -431,7 +431,7 @@ mod tests { let (g, _no_timeout) = C.wait_timeout(g, Duration::nanoseconds(1000)).unwrap(); // spurious wakeups mean this isn't necessarily true // assert!(!no_timeout); - let _t = Thread::spawn(move || { + let _t = thread::spawn(move || { let _g = M.lock().unwrap(); C.notify_one(); }); @@ -452,7 +452,7 @@ mod tests { assert!(!success); let (tx, rx) = channel(); - let _t = Thread::scoped(move || { + let _t = thread::spawn(move || { rx.recv().unwrap(); let g = M.lock().unwrap(); S.store(1, Ordering::SeqCst); @@ -492,7 +492,7 @@ mod tests { static C: StaticCondvar = CONDVAR_INIT; let mut g = M1.lock().unwrap(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let _g = M1.lock().unwrap(); C.notify_one(); }); diff --git a/src/libstd/sync/future.rs b/src/libstd/sync/future.rs index a230e35dac8c3..ae5c1e1b4a56c 100644 --- a/src/libstd/sync/future.rs +++ b/src/libstd/sync/future.rs @@ -38,7 +38,7 @@ use core::mem::replace; use self::FutureState::*; use sync::mpsc::{Receiver, channel}; use thunk::{Thunk}; -use thread::Thread; +use thread; /// A type encapsulating the result of a computation which may not be complete pub struct Future { @@ -143,7 +143,7 @@ impl Future { let (tx, rx) = channel(); - Thread::spawn(move || { + thread::spawn(move || { // Don't panic if the other end has hung up let _ = tx.send(blk()); }); @@ -157,7 +157,7 @@ mod test { use prelude::v1::*; use sync::mpsc::channel; use sync::Future; - use thread::Thread; + use thread; #[test] fn test_from_value() { @@ -215,7 +215,7 @@ mod test { let expected = "schlorf"; let (tx, rx) = channel(); let f = Future::spawn(move|| { expected }); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut f = f; tx.send(f.get()).unwrap(); }); diff --git a/src/libstd/sync/mpsc/blocking.rs b/src/libstd/sync/mpsc/blocking.rs index 61ffb532d36ad..69b1e242b154d 100644 --- a/src/libstd/sync/mpsc/blocking.rs +++ b/src/libstd/sync/mpsc/blocking.rs @@ -10,7 +10,7 @@ //! Generic support for building blocking abstractions. -use thread::Thread; +use thread::{self, Thread}; use sync::atomic::{AtomicBool, ATOMIC_BOOL_INIT, Ordering}; use sync::Arc; use marker::{Sync, Send}; @@ -40,7 +40,7 @@ impl !Sync for WaitToken {} pub fn tokens() -> (WaitToken, SignalToken) { let inner = Arc::new(Inner { - thread: Thread::current(), + thread: thread::current(), woken: ATOMIC_BOOL_INIT, }); let wait_token = WaitToken { @@ -80,7 +80,7 @@ impl SignalToken { impl WaitToken { pub fn wait(self) { while !self.inner.woken.load(Ordering::SeqCst) { - Thread::park() + thread::park() } } } diff --git a/src/libstd/sync/mpsc/mod.rs b/src/libstd/sync/mpsc/mod.rs index d783acd57ac04..862745a05eb8e 100644 --- a/src/libstd/sync/mpsc/mod.rs +++ b/src/libstd/sync/mpsc/mod.rs @@ -53,12 +53,12 @@ //! Simple usage: //! //! ``` -//! use std::thread::Thread; +//! use std::thread; //! use std::sync::mpsc::channel; //! //! // Create a simple streaming channel //! let (tx, rx) = channel(); -//! Thread::spawn(move|| { +//! thread::spawn(move|| { //! tx.send(10).unwrap(); //! }); //! assert_eq!(rx.recv().unwrap(), 10); @@ -67,7 +67,7 @@ //! Shared usage: //! //! ``` -//! use std::thread::Thread; +//! use std::thread; //! use std::sync::mpsc::channel; //! //! // Create a shared channel that can be sent along from many threads @@ -76,7 +76,7 @@ //! let (tx, rx) = channel(); //! for i in 0..10 { //! let tx = tx.clone(); -//! Thread::spawn(move|| { +//! thread::spawn(move|| { //! tx.send(i).unwrap(); //! }); //! } @@ -102,11 +102,11 @@ //! Synchronous channels: //! //! ``` -//! use std::thread::Thread; +//! use std::thread; //! use std::sync::mpsc::sync_channel; //! //! let (tx, rx) = sync_channel::(0); -//! Thread::spawn(move|| { +//! thread::spawn(move|| { //! // This will wait for the parent task to start receiving //! tx.send(53).unwrap(); //! }); @@ -467,14 +467,14 @@ impl UnsafeFlavor for Receiver { /// /// ``` /// use std::sync::mpsc::channel; -/// use std::thread::Thread; +/// use std::thread; /// /// // tx is is the sending half (tx for transmission), and rx is the receiving /// // half (rx for receiving). /// let (tx, rx) = channel(); /// /// // Spawn off an expensive computation -/// Thread::spawn(move|| { +/// thread::spawn(move|| { /// # fn expensive_computation() {} /// tx.send(expensive_computation()).unwrap(); /// }); @@ -509,14 +509,14 @@ pub fn channel() -> (Sender, Receiver) { /// /// ``` /// use std::sync::mpsc::sync_channel; -/// use std::thread::Thread; +/// use std::thread; /// /// let (tx, rx) = sync_channel(1); /// /// // this returns immediately /// tx.send(1).unwrap(); /// -/// Thread::spawn(move|| { +/// thread::spawn(move|| { /// // this will block until the previous message has been received /// tx.send(2).unwrap(); /// }); @@ -1026,7 +1026,7 @@ mod test { use std::env; use super::*; - use thread::Thread; + use thread; pub fn stress_factor() -> uint { match env::var("RUST_TEST_STRESS") { @@ -1069,7 +1069,7 @@ mod test { #[test] fn smoke_threads() { let (tx, rx) = channel::(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { tx.send(1).unwrap(); }); assert_eq!(rx.recv().unwrap(), 1); @@ -1101,7 +1101,7 @@ mod test { #[test] fn port_gone_concurrent() { let (tx, rx) = channel::(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { rx.recv().unwrap(); }); while tx.send(1).is_ok() {} @@ -1111,7 +1111,7 @@ mod test { fn port_gone_concurrent_shared() { let (tx, rx) = channel::(); let tx2 = tx.clone(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { rx.recv().unwrap(); }); while tx.send(1).is_ok() && tx2.send(1).is_ok() {} @@ -1136,7 +1136,7 @@ mod test { #[test] fn chan_gone_concurrent() { let (tx, rx) = channel::(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { tx.send(1).unwrap(); tx.send(1).unwrap(); }); @@ -1146,7 +1146,7 @@ mod test { #[test] fn stress() { let (tx, rx) = channel::(); - let t = Thread::scoped(move|| { + let t = thread::spawn(move|| { for _ in 0u..10000 { tx.send(1).unwrap(); } }); for _ in 0u..10000 { @@ -1161,7 +1161,7 @@ mod test { static NTHREADS: uint = 8; let (tx, rx) = channel::(); - let t = Thread::scoped(move|| { + let t = thread::spawn(move|| { for _ in 0..AMT * NTHREADS { assert_eq!(rx.recv().unwrap(), 1); } @@ -1173,7 +1173,7 @@ mod test { for _ in 0..NTHREADS { let tx = tx.clone(); - Thread::spawn(move|| { + thread::spawn(move|| { for _ in 0..AMT { tx.send(1).unwrap(); } }); } @@ -1185,14 +1185,14 @@ mod test { fn send_from_outside_runtime() { let (tx1, rx1) = channel::<()>(); let (tx2, rx2) = channel::(); - let t1 = Thread::scoped(move|| { + let t1 = thread::spawn(move|| { tx1.send(()).unwrap(); for _ in 0..40 { assert_eq!(rx2.recv().unwrap(), 1); } }); rx1.recv().unwrap(); - let t2 = Thread::scoped(move|| { + let t2 = thread::spawn(move|| { for _ in 0..40 { tx2.send(1).unwrap(); } @@ -1204,7 +1204,7 @@ mod test { #[test] fn recv_from_outside_runtime() { let (tx, rx) = channel::(); - let t = Thread::scoped(move|| { + let t = thread::spawn(move|| { for _ in 0..40 { assert_eq!(rx.recv().unwrap(), 1); } @@ -1219,11 +1219,11 @@ mod test { fn no_runtime() { let (tx1, rx1) = channel::(); let (tx2, rx2) = channel::(); - let t1 = Thread::scoped(move|| { + let t1 = thread::spawn(move|| { assert_eq!(rx1.recv().unwrap(), 1); tx2.send(2).unwrap(); }); - let t2 = Thread::scoped(move|| { + let t2 = thread::spawn(move|| { tx1.send(1).unwrap(); assert_eq!(rx2.recv().unwrap(), 2); }); @@ -1256,7 +1256,7 @@ mod test { #[test] fn oneshot_single_thread_recv_chan_close() { // Receiving on a closed chan will panic - let res = Thread::scoped(move|| { + let res = thread::spawn(move|| { let (tx, rx) = channel::(); drop(tx); rx.recv().unwrap(); @@ -1325,7 +1325,7 @@ mod test { #[test] fn oneshot_multi_task_recv_then_send() { let (tx, rx) = channel::>(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { assert!(rx.recv().unwrap() == box 10); }); @@ -1335,10 +1335,10 @@ mod test { #[test] fn oneshot_multi_task_recv_then_close() { let (tx, rx) = channel::>(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { drop(tx); }); - let res = Thread::scoped(move|| { + let res = thread::spawn(move|| { assert!(rx.recv().unwrap() == box 10); }).join(); assert!(res.is_err()); @@ -1348,7 +1348,7 @@ mod test { fn oneshot_multi_thread_close_stress() { for _ in 0..stress_factor() { let (tx, rx) = channel::(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { drop(rx); }); drop(tx); @@ -1359,10 +1359,10 @@ mod test { fn oneshot_multi_thread_send_close_stress() { for _ in 0..stress_factor() { let (tx, rx) = channel::(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { drop(rx); }); - let _ = Thread::scoped(move|| { + let _ = thread::spawn(move|| { tx.send(1).unwrap(); }).join(); } @@ -1372,14 +1372,14 @@ mod test { fn oneshot_multi_thread_recv_close_stress() { for _ in 0..stress_factor() { let (tx, rx) = channel::(); - Thread::spawn(move|| { - let res = Thread::scoped(move|| { + thread::spawn(move|| { + let res = thread::spawn(move|| { rx.recv().unwrap(); }).join(); assert!(res.is_err()); }); - let _t = Thread::spawn(move|| { - Thread::spawn(move|| { + let _t = thread::spawn(move|| { + thread::spawn(move|| { drop(tx); }); }); @@ -1390,7 +1390,7 @@ mod test { fn oneshot_multi_thread_send_recv_stress() { for _ in 0..stress_factor() { let (tx, rx) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { tx.send(box 10).unwrap(); }); assert!(rx.recv().unwrap() == box 10); @@ -1408,7 +1408,7 @@ mod test { fn send(tx: Sender>, i: int) { if i == 10 { return } - Thread::spawn(move|| { + thread::spawn(move|| { tx.send(box i).unwrap(); send(tx, i + 1); }); @@ -1417,7 +1417,7 @@ mod test { fn recv(rx: Receiver>, i: int) { if i == 10 { return } - Thread::spawn(move|| { + thread::spawn(move|| { assert!(rx.recv().unwrap() == box i); recv(rx, i + 1); }); @@ -1439,7 +1439,7 @@ mod test { let total = stress_factor() + 100; for _ in 0..total { let tx = tx.clone(); - Thread::spawn(move|| { + thread::spawn(move|| { tx.send(()).unwrap(); }); } @@ -1454,7 +1454,7 @@ mod test { let (tx, rx) = channel::(); let (total_tx, total_rx) = channel::(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut acc = 0; for x in rx.iter() { acc += x; @@ -1474,7 +1474,7 @@ mod test { let (tx, rx) = channel::(); let (count_tx, count_rx) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut count = 0; for x in rx.iter() { if count >= 3 { @@ -1499,7 +1499,7 @@ mod test { let (tx1, rx1) = channel::(); let (tx2, rx2) = channel::<()>(); let (tx3, rx3) = channel::<()>(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { rx2.recv().unwrap(); tx1.send(1).unwrap(); tx3.send(()).unwrap(); @@ -1524,13 +1524,13 @@ mod test { fn destroy_upgraded_shared_port_when_sender_still_active() { let (tx, rx) = channel(); let (tx2, rx2) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { rx.recv().unwrap(); // wait on a oneshot drop(rx); // destroy a shared tx2.send(()).unwrap(); }); // make sure the other task has gone to sleep - for _ in 0u..5000 { Thread::yield_now(); } + for _ in 0u..5000 { thread::yield_now(); } // upgrade to a shared chan and send a message let t = tx.clone(); @@ -1547,7 +1547,7 @@ mod sync_tests { use prelude::v1::*; use std::env; - use thread::Thread; + use thread; use super::*; pub fn stress_factor() -> uint { @@ -1583,7 +1583,7 @@ mod sync_tests { #[test] fn smoke_threads() { let (tx, rx) = sync_channel::(0); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { tx.send(1).unwrap(); }); assert_eq!(rx.recv().unwrap(), 1); @@ -1608,7 +1608,7 @@ mod sync_tests { #[test] fn port_gone_concurrent() { let (tx, rx) = sync_channel::(0); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { rx.recv().unwrap(); }); while tx.send(1).is_ok() {} @@ -1618,7 +1618,7 @@ mod sync_tests { fn port_gone_concurrent_shared() { let (tx, rx) = sync_channel::(0); let tx2 = tx.clone(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { rx.recv().unwrap(); }); while tx.send(1).is_ok() && tx2.send(1).is_ok() {} @@ -1643,7 +1643,7 @@ mod sync_tests { #[test] fn chan_gone_concurrent() { let (tx, rx) = sync_channel::(0); - Thread::spawn(move|| { + thread::spawn(move|| { tx.send(1).unwrap(); tx.send(1).unwrap(); }); @@ -1653,7 +1653,7 @@ mod sync_tests { #[test] fn stress() { let (tx, rx) = sync_channel::(0); - Thread::spawn(move|| { + thread::spawn(move|| { for _ in 0u..10000 { tx.send(1).unwrap(); } }); for _ in 0u..10000 { @@ -1668,7 +1668,7 @@ mod sync_tests { let (tx, rx) = sync_channel::(0); let (dtx, drx) = sync_channel::<()>(0); - Thread::spawn(move|| { + thread::spawn(move|| { for _ in 0..AMT * NTHREADS { assert_eq!(rx.recv().unwrap(), 1); } @@ -1681,7 +1681,7 @@ mod sync_tests { for _ in 0..NTHREADS { let tx = tx.clone(); - Thread::spawn(move|| { + thread::spawn(move|| { for _ in 0..AMT { tx.send(1).unwrap(); } }); } @@ -1714,7 +1714,7 @@ mod sync_tests { #[test] fn oneshot_single_thread_recv_chan_close() { // Receiving on a closed chan will panic - let res = Thread::scoped(move|| { + let res = thread::spawn(move|| { let (tx, rx) = sync_channel::(0); drop(tx); rx.recv().unwrap(); @@ -1789,7 +1789,7 @@ mod sync_tests { #[test] fn oneshot_multi_task_recv_then_send() { let (tx, rx) = sync_channel::>(0); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { assert!(rx.recv().unwrap() == box 10); }); @@ -1799,10 +1799,10 @@ mod sync_tests { #[test] fn oneshot_multi_task_recv_then_close() { let (tx, rx) = sync_channel::>(0); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { drop(tx); }); - let res = Thread::scoped(move|| { + let res = thread::spawn(move|| { assert!(rx.recv().unwrap() == box 10); }).join(); assert!(res.is_err()); @@ -1812,7 +1812,7 @@ mod sync_tests { fn oneshot_multi_thread_close_stress() { for _ in 0..stress_factor() { let (tx, rx) = sync_channel::(0); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { drop(rx); }); drop(tx); @@ -1823,10 +1823,10 @@ mod sync_tests { fn oneshot_multi_thread_send_close_stress() { for _ in 0..stress_factor() { let (tx, rx) = sync_channel::(0); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { drop(rx); }); - let _ = Thread::scoped(move || { + let _ = thread::spawn(move || { tx.send(1).unwrap(); }).join(); } @@ -1836,14 +1836,14 @@ mod sync_tests { fn oneshot_multi_thread_recv_close_stress() { for _ in 0..stress_factor() { let (tx, rx) = sync_channel::(0); - let _t = Thread::spawn(move|| { - let res = Thread::scoped(move|| { + let _t = thread::spawn(move|| { + let res = thread::spawn(move|| { rx.recv().unwrap(); }).join(); assert!(res.is_err()); }); - let _t = Thread::spawn(move|| { - Thread::spawn(move|| { + let _t = thread::spawn(move|| { + thread::spawn(move|| { drop(tx); }); }); @@ -1854,7 +1854,7 @@ mod sync_tests { fn oneshot_multi_thread_send_recv_stress() { for _ in 0..stress_factor() { let (tx, rx) = sync_channel::>(0); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { tx.send(box 10).unwrap(); }); assert!(rx.recv().unwrap() == box 10); @@ -1872,7 +1872,7 @@ mod sync_tests { fn send(tx: SyncSender>, i: int) { if i == 10 { return } - Thread::spawn(move|| { + thread::spawn(move|| { tx.send(box i).unwrap(); send(tx, i + 1); }); @@ -1881,7 +1881,7 @@ mod sync_tests { fn recv(rx: Receiver>, i: int) { if i == 10 { return } - Thread::spawn(move|| { + thread::spawn(move|| { assert!(rx.recv().unwrap() == box i); recv(rx, i + 1); }); @@ -1903,7 +1903,7 @@ mod sync_tests { let total = stress_factor() + 100; for _ in 0..total { let tx = tx.clone(); - Thread::spawn(move|| { + thread::spawn(move|| { tx.send(()).unwrap(); }); } @@ -1918,7 +1918,7 @@ mod sync_tests { let (tx, rx) = sync_channel::(0); let (total_tx, total_rx) = sync_channel::(0); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut acc = 0; for x in rx.iter() { acc += x; @@ -1938,7 +1938,7 @@ mod sync_tests { let (tx, rx) = sync_channel::(0); let (count_tx, count_rx) = sync_channel(0); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut count = 0; for x in rx.iter() { if count >= 3 { @@ -1963,7 +1963,7 @@ mod sync_tests { let (tx1, rx1) = sync_channel::(1); let (tx2, rx2) = sync_channel::<()>(1); let (tx3, rx3) = sync_channel::<()>(1); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { rx2.recv().unwrap(); tx1.send(1).unwrap(); tx3.send(()).unwrap(); @@ -1988,13 +1988,13 @@ mod sync_tests { fn destroy_upgraded_shared_port_when_sender_still_active() { let (tx, rx) = sync_channel::<()>(0); let (tx2, rx2) = sync_channel::<()>(0); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { rx.recv().unwrap(); // wait on a oneshot drop(rx); // destroy a shared tx2.send(()).unwrap(); }); // make sure the other task has gone to sleep - for _ in 0u..5000 { Thread::yield_now(); } + for _ in 0u..5000 { thread::yield_now(); } // upgrade to a shared chan and send a message let t = tx.clone(); @@ -2008,14 +2008,14 @@ mod sync_tests { #[test] fn send1() { let (tx, rx) = sync_channel::(0); - let _t = Thread::spawn(move|| { rx.recv().unwrap(); }); + let _t = thread::spawn(move|| { rx.recv().unwrap(); }); assert_eq!(tx.send(1), Ok(())); } #[test] fn send2() { let (tx, rx) = sync_channel::(0); - let _t = Thread::spawn(move|| { drop(rx); }); + let _t = thread::spawn(move|| { drop(rx); }); assert!(tx.send(1).is_err()); } @@ -2023,7 +2023,7 @@ mod sync_tests { fn send3() { let (tx, rx) = sync_channel::(1); assert_eq!(tx.send(1), Ok(())); - let _t =Thread::spawn(move|| { drop(rx); }); + let _t =thread::spawn(move|| { drop(rx); }); assert!(tx.send(1).is_err()); } @@ -2033,11 +2033,11 @@ mod sync_tests { let tx2 = tx.clone(); let (done, donerx) = channel(); let done2 = done.clone(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { assert!(tx.send(1).is_err()); done.send(()).unwrap(); }); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { assert!(tx2.send(2).is_err()); done2.send(()).unwrap(); }); @@ -2073,7 +2073,7 @@ mod sync_tests { let (tx1, rx1) = sync_channel::<()>(3); let (tx2, rx2) = sync_channel::<()>(3); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { rx1.recv().unwrap(); tx2.try_send(()).unwrap(); }); diff --git a/src/libstd/sync/mpsc/mpsc_queue.rs b/src/libstd/sync/mpsc/mpsc_queue.rs index 3980d2a1fefb5..c374f8bbcee51 100644 --- a/src/libstd/sync/mpsc/mpsc_queue.rs +++ b/src/libstd/sync/mpsc/mpsc_queue.rs @@ -160,7 +160,7 @@ mod tests { use sync::mpsc::channel; use super::{Queue, Data, Empty, Inconsistent}; use sync::Arc; - use thread::Thread; + use thread; #[test] fn test_full() { @@ -184,7 +184,7 @@ mod tests { for _ in 0..nthreads { let tx = tx.clone(); let q = q.clone(); - Thread::spawn(move|| { + thread::spawn(move|| { for i in 0..nmsgs { q.push(i); } diff --git a/src/libstd/sync/mpsc/select.rs b/src/libstd/sync/mpsc/select.rs index 87b2fe8f100c3..652a9ebb020e9 100644 --- a/src/libstd/sync/mpsc/select.rs +++ b/src/libstd/sync/mpsc/select.rs @@ -347,7 +347,7 @@ impl Iterator for Packets { mod test { use prelude::v1::*; - use thread::Thread; + use thread; use sync::mpsc::*; // Don't use the libstd version so we can pull in the right Select structure @@ -427,11 +427,11 @@ mod test { let (_tx2, rx2) = channel::(); let (tx3, rx3) = channel::(); - let _t = Thread::spawn(move|| { - for _ in 0u..20 { Thread::yield_now(); } + let _t = thread::spawn(move|| { + for _ in 0u..20 { thread::yield_now(); } tx1.send(1).unwrap(); rx3.recv().unwrap(); - for _ in 0u..20 { Thread::yield_now(); } + for _ in 0u..20 { thread::yield_now(); } }); select! { @@ -451,8 +451,8 @@ mod test { let (tx2, rx2) = channel::(); let (tx3, rx3) = channel::<()>(); - let _t = Thread::spawn(move|| { - for _ in 0u..20 { Thread::yield_now(); } + let _t = thread::spawn(move|| { + for _ in 0u..20 { thread::yield_now(); } tx1.send(1).unwrap(); tx2.send(2).unwrap(); rx3.recv().unwrap(); @@ -478,7 +478,7 @@ mod test { let (tx2, rx2) = channel::(); let (tx3, rx3) = channel::<()>(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { for i in 0..AMT { if i % 2 == 0 { tx1.send(i).unwrap(); @@ -504,7 +504,7 @@ mod test { let (_tx2, rx2) = channel::(); let (tx3, rx3) = channel::<()>(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { rx3.recv().unwrap(); tx1.clone(); assert_eq!(rx3.try_recv(), Err(TryRecvError::Empty)); @@ -526,7 +526,7 @@ mod test { let (_tx2, rx2) = channel::(); let (tx3, rx3) = channel::<()>(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { rx3.recv().unwrap(); tx1.clone(); assert_eq!(rx3.try_recv(), Err(TryRecvError::Empty)); @@ -547,7 +547,7 @@ mod test { let (tx1, rx1) = channel::<()>(); let (tx2, rx2) = channel::<()>(); let (tx3, rx3) = channel::<()>(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let s = Select::new(); let mut h1 = s.handle(&rx1); let mut h2 = s.handle(&rx2); @@ -557,7 +557,7 @@ mod test { tx3.send(()).unwrap(); }); - for _ in 0u..1000 { Thread::yield_now(); } + for _ in 0u..1000 { thread::yield_now(); } drop(tx1.clone()); tx2.send(()).unwrap(); rx3.recv().unwrap(); @@ -663,14 +663,14 @@ mod test { fn oneshot_data_waiting() { let (tx1, rx1) = channel(); let (tx2, rx2) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { select! { _n = rx1.recv() => {} } tx2.send(()).unwrap(); }); - for _ in 0u..100 { Thread::yield_now() } + for _ in 0u..100 { thread::yield_now() } tx1.send(()).unwrap(); rx2.recv().unwrap(); } @@ -683,14 +683,14 @@ mod test { tx1.send(()).unwrap(); rx1.recv().unwrap(); rx1.recv().unwrap(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { select! { _n = rx1.recv() => {} } tx2.send(()).unwrap(); }); - for _ in 0u..100 { Thread::yield_now() } + for _ in 0u..100 { thread::yield_now() } tx1.send(()).unwrap(); rx2.recv().unwrap(); } @@ -702,14 +702,14 @@ mod test { drop(tx1.clone()); tx1.send(()).unwrap(); rx1.recv().unwrap(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { select! { _n = rx1.recv() => {} } tx2.send(()).unwrap(); }); - for _ in 0u..100 { Thread::yield_now() } + for _ in 0u..100 { thread::yield_now() } tx1.send(()).unwrap(); rx2.recv().unwrap(); } @@ -726,8 +726,8 @@ mod test { #[test] fn sync2() { let (tx, rx) = sync_channel::(0); - let _t = Thread::spawn(move|| { - for _ in 0u..100 { Thread::yield_now() } + let _t = thread::spawn(move|| { + for _ in 0u..100 { thread::yield_now() } tx.send(1).unwrap(); }); select! { @@ -739,8 +739,8 @@ mod test { fn sync3() { let (tx1, rx1) = sync_channel::(0); let (tx2, rx2): (Sender, Receiver) = channel(); - let _t = Thread::spawn(move|| { tx1.send(1).unwrap(); }); - let _t = Thread::spawn(move|| { tx2.send(2).unwrap(); }); + let _t = thread::spawn(move|| { tx1.send(1).unwrap(); }); + let _t = thread::spawn(move|| { tx2.send(2).unwrap(); }); select! { n = rx1.recv() => { let n = n.unwrap(); diff --git a/src/libstd/sync/mpsc/shared.rs b/src/libstd/sync/mpsc/shared.rs index 6c31fb925911e..729e7991f97cf 100644 --- a/src/libstd/sync/mpsc/shared.rs +++ b/src/libstd/sync/mpsc/shared.rs @@ -31,7 +31,7 @@ use sync::mpsc::mpsc_queue as mpsc; use sync::mpsc::select::StartResult::*; use sync::mpsc::select::StartResult; use sync::{Mutex, MutexGuard}; -use thread::Thread; +use thread; const DISCONNECTED: isize = isize::MIN; const FUDGE: isize = 1024; @@ -194,7 +194,7 @@ impl Packet { match self.queue.pop() { mpsc::Data(..) => {} mpsc::Empty => break, - mpsc::Inconsistent => Thread::yield_now(), + mpsc::Inconsistent => thread::yield_now(), } } // maybe we're done, if we're not the last ones @@ -283,7 +283,7 @@ impl Packet { mpsc::Inconsistent => { let data; loop { - Thread::yield_now(); + thread::yield_now(); match self.queue.pop() { mpsc::Data(t) => { data = t; break } mpsc::Empty => panic!("inconsistent => empty"), @@ -460,7 +460,7 @@ impl Packet { drop(self.take_to_wake()); } else { while self.to_wake.load(Ordering::SeqCst) != 0 { - Thread::yield_now(); + thread::yield_now(); } } // if the number of steals is -1, it was the pre-emptive -1 steal diff --git a/src/libstd/sync/mpsc/spsc_queue.rs b/src/libstd/sync/mpsc/spsc_queue.rs index f0558c33d1ec8..c03bf02481855 100644 --- a/src/libstd/sync/mpsc/spsc_queue.rs +++ b/src/libstd/sync/mpsc/spsc_queue.rs @@ -246,7 +246,7 @@ mod test { use sync::Arc; use super::Queue; - use thread::Thread; + use thread; use sync::mpsc::channel; #[test] @@ -324,7 +324,7 @@ mod test { let (tx, rx) = channel(); let q2 = q.clone(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { for _ in 0u..100000 { loop { match q2.pop() { diff --git a/src/libstd/sync/mpsc/stream.rs b/src/libstd/sync/mpsc/stream.rs index ab9bd6b2ed7f6..2d528662f64fc 100644 --- a/src/libstd/sync/mpsc/stream.rs +++ b/src/libstd/sync/mpsc/stream.rs @@ -26,7 +26,7 @@ use core::prelude::*; use core::cmp; use core::isize; -use thread::Thread; +use thread; use sync::atomic::{AtomicIsize, AtomicUsize, Ordering, AtomicBool}; use sync::mpsc::Receiver; @@ -440,7 +440,7 @@ impl Packet { drop(self.take_to_wake()); } else { while self.to_wake.load(Ordering::SeqCst) != 0 { - Thread::yield_now(); + thread::yield_now(); } } assert_eq!(self.steals, 0); diff --git a/src/libstd/sync/mutex.rs b/src/libstd/sync/mutex.rs index 74692c1273c27..d7e8419f19f65 100644 --- a/src/libstd/sync/mutex.rs +++ b/src/libstd/sync/mutex.rs @@ -47,7 +47,7 @@ use sys_common::mutex as sys; /// /// ```rust /// use std::sync::{Arc, Mutex}; -/// use std::thread::Thread; +/// use std::thread; /// use std::sync::mpsc::channel; /// /// const N: uint = 10; @@ -62,7 +62,7 @@ use sys_common::mutex as sys; /// let (tx, rx) = channel(); /// for _ in 0u..10 { /// let (data, tx) = (data.clone(), tx.clone()); -/// Thread::spawn(move || { +/// thread::spawn(move || { /// // The shared static can only be accessed once the lock is held. /// // Our non-atomic increment is safe because we're the only thread /// // which can access the shared state when the lock is held. @@ -85,12 +85,12 @@ use sys_common::mutex as sys; /// /// ```rust /// use std::sync::{Arc, Mutex}; -/// use std::thread::Thread; +/// use std::thread; /// /// let lock = Arc::new(Mutex::new(0u)); /// let lock2 = lock.clone(); /// -/// let _ = Thread::scoped(move || -> () { +/// let _ = thread::spawn(move || -> () { /// // This thread will acquire the mutex first, unwrapping the result of /// // `lock` because the lock has not been poisoned. /// let _lock = lock2.lock().unwrap(); @@ -350,7 +350,7 @@ mod test { use sync::mpsc::channel; use sync::{Arc, Mutex, StaticMutex, MUTEX_INIT, Condvar}; - use thread::Thread; + use thread; struct Packet(Arc<(Mutex, Condvar)>); @@ -393,9 +393,9 @@ mod test { let (tx, rx) = channel(); for _ in 0..K { let tx2 = tx.clone(); - Thread::spawn(move|| { inc(); tx2.send(()).unwrap(); }); + thread::spawn(move|| { inc(); tx2.send(()).unwrap(); }); let tx2 = tx.clone(); - Thread::spawn(move|| { inc(); tx2.send(()).unwrap(); }); + thread::spawn(move|| { inc(); tx2.send(()).unwrap(); }); } drop(tx); @@ -419,7 +419,7 @@ mod test { let packet = Packet(Arc::new((Mutex::new(false), Condvar::new()))); let packet2 = Packet(packet.0.clone()); let (tx, rx) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { // wait until parent gets in rx.recv().unwrap(); let &(ref lock, ref cvar) = &*packet2.0; @@ -443,7 +443,7 @@ mod test { let packet2 = Packet(packet.0.clone()); let (tx, rx) = channel(); - let _t = Thread::spawn(move || -> () { + let _t = thread::spawn(move || -> () { rx.recv().unwrap(); let &(ref lock, ref cvar) = &*packet2.0; let _g = lock.lock().unwrap(); @@ -471,7 +471,7 @@ mod test { let arc = Arc::new(Mutex::new(1)); assert!(!arc.is_poisoned()); let arc2 = arc.clone(); - let _ = Thread::scoped(move|| { + let _ = thread::spawn(move|| { let lock = arc2.lock().unwrap(); assert_eq!(*lock, 2); }).join(); @@ -486,7 +486,7 @@ mod test { let arc = Arc::new(Mutex::new(1)); let arc2 = Arc::new(Mutex::new(arc)); let (tx, rx) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let lock = arc2.lock().unwrap(); let lock2 = lock.lock().unwrap(); assert_eq!(*lock2, 1); @@ -499,7 +499,7 @@ mod test { fn test_mutex_arc_access_in_unwind() { let arc = Arc::new(Mutex::new(1)); let arc2 = arc.clone(); - let _ = Thread::scoped(move|| -> () { + let _ = thread::spawn(move|| -> () { struct Unwinder { i: Arc>, } diff --git a/src/libstd/sync/once.rs b/src/libstd/sync/once.rs index 29c2051e5adc4..1e87c0d612bdc 100644 --- a/src/libstd/sync/once.rs +++ b/src/libstd/sync/once.rs @@ -127,7 +127,7 @@ impl Once { mod test { use prelude::v1::*; - use thread::Thread; + use thread; use super::{ONCE_INIT, Once}; use sync::mpsc::channel; @@ -149,8 +149,8 @@ mod test { let (tx, rx) = channel(); for _ in 0u..10 { let tx = tx.clone(); - Thread::spawn(move|| { - for _ in 0u..4 { Thread::yield_now() } + thread::spawn(move|| { + for _ in 0u..4 { thread::yield_now() } unsafe { O.call_once(|| { assert!(!run); diff --git a/src/libstd/sync/poison.rs b/src/libstd/sync/poison.rs index a93bd31f5ae38..32c8150ba4070 100644 --- a/src/libstd/sync/poison.rs +++ b/src/libstd/sync/poison.rs @@ -13,7 +13,7 @@ use prelude::v1::*; use cell::UnsafeCell; use error::{Error, FromError}; use fmt; -use thread::Thread; +use thread; pub struct Flag { failed: UnsafeCell } pub const FLAG_INIT: Flag = Flag { failed: UnsafeCell { value: false } }; @@ -21,7 +21,7 @@ pub const FLAG_INIT: Flag = Flag { failed: UnsafeCell { value: false } }; impl Flag { #[inline] pub fn borrow(&self) -> LockResult { - let ret = Guard { panicking: Thread::panicking() }; + let ret = Guard { panicking: thread::panicking() }; if unsafe { *self.failed.get() } { Err(PoisonError::new(ret)) } else { @@ -31,7 +31,7 @@ impl Flag { #[inline] pub fn done(&self, guard: &Guard) { - if !guard.panicking && Thread::panicking() { + if !guard.panicking && thread::panicking() { unsafe { *self.failed.get() = true; } } } diff --git a/src/libstd/sync/rwlock.rs b/src/libstd/sync/rwlock.rs index c4f1f2ccadddd..402542b8bdc32 100644 --- a/src/libstd/sync/rwlock.rs +++ b/src/libstd/sync/rwlock.rs @@ -400,7 +400,7 @@ mod tests { use rand::{self, Rng}; use sync::mpsc::channel; - use thread::Thread; + use thread; use sync::{Arc, RwLock, StaticRwLock, RW_LOCK_INIT}; #[test] @@ -431,7 +431,7 @@ mod tests { let (tx, rx) = channel::<()>(); for _ in 0..N { let tx = tx.clone(); - Thread::spawn(move|| { + thread::spawn(move|| { let mut rng = rand::thread_rng(); for _ in 0..M { if rng.gen_weighted_bool(N) { @@ -452,7 +452,7 @@ mod tests { fn test_rw_arc_poison_wr() { let arc = Arc::new(RwLock::new(1)); let arc2 = arc.clone(); - let _: Result = Thread::scoped(move|| { + let _: Result = thread::spawn(move|| { let _lock = arc2.write().unwrap(); panic!(); }).join(); @@ -464,7 +464,7 @@ mod tests { let arc = Arc::new(RwLock::new(1)); assert!(!arc.is_poisoned()); let arc2 = arc.clone(); - let _: Result = Thread::scoped(move|| { + let _: Result = thread::spawn(move|| { let _lock = arc2.write().unwrap(); panic!(); }).join(); @@ -476,7 +476,7 @@ mod tests { fn test_rw_arc_no_poison_rr() { let arc = Arc::new(RwLock::new(1)); let arc2 = arc.clone(); - let _: Result = Thread::scoped(move|| { + let _: Result = thread::spawn(move|| { let _lock = arc2.read().unwrap(); panic!(); }).join(); @@ -487,7 +487,7 @@ mod tests { fn test_rw_arc_no_poison_rw() { let arc = Arc::new(RwLock::new(1)); let arc2 = arc.clone(); - let _: Result = Thread::scoped(move|| { + let _: Result = thread::spawn(move|| { let _lock = arc2.read().unwrap(); panic!() }).join(); @@ -501,12 +501,12 @@ mod tests { let arc2 = arc.clone(); let (tx, rx) = channel(); - Thread::spawn(move|| { + thread::spawn(move|| { let mut lock = arc2.write().unwrap(); for _ in 0u..10 { let tmp = *lock; *lock = -1; - Thread::yield_now(); + thread::yield_now(); *lock = tmp + 1; } tx.send(()).unwrap(); @@ -516,7 +516,7 @@ mod tests { let mut children = Vec::new(); for _ in 0u..5 { let arc3 = arc.clone(); - children.push(Thread::scoped(move|| { + children.push(thread::spawn(move|| { let lock = arc3.read().unwrap(); assert!(*lock >= 0); })); @@ -537,7 +537,7 @@ mod tests { fn test_rw_arc_access_in_unwind() { let arc = Arc::new(RwLock::new(1)); let arc2 = arc.clone(); - let _ = Thread::scoped(move|| -> () { + let _ = thread::spawn(move|| -> () { struct Unwinder { i: Arc>, } diff --git a/src/libstd/sync/semaphore.rs b/src/libstd/sync/semaphore.rs index 0304b898884cc..410e1c11bb9a9 100644 --- a/src/libstd/sync/semaphore.rs +++ b/src/libstd/sync/semaphore.rs @@ -114,7 +114,7 @@ mod tests { use sync::Arc; use super::Semaphore; use sync::mpsc::channel; - use thread::Thread; + use thread; #[test] fn test_sem_acquire_release() { @@ -134,7 +134,7 @@ mod tests { fn test_sem_as_mutex() { let s = Arc::new(Semaphore::new(1)); let s2 = s.clone(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let _g = s2.access(); }); let _g = s.access(); @@ -146,7 +146,7 @@ mod tests { let (tx, rx) = channel(); let s = Arc::new(Semaphore::new(0)); let s2 = s.clone(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { s2.acquire(); tx.send(()).unwrap(); }); @@ -157,7 +157,7 @@ mod tests { let (tx, rx) = channel(); let s = Arc::new(Semaphore::new(0)); let s2 = s.clone(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { s2.release(); let _ = rx.recv(); }); @@ -173,7 +173,7 @@ mod tests { let s2 = s.clone(); let (tx1, rx1) = channel(); let (tx2, rx2) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let _g = s2.access(); let _ = rx2.recv(); tx1.send(()).unwrap(); @@ -190,7 +190,7 @@ mod tests { let (tx, rx) = channel(); { let _g = s.access(); - Thread::spawn(move|| { + thread::spawn(move|| { tx.send(()).unwrap(); drop(s2.access()); tx.send(()).unwrap(); diff --git a/src/libstd/sync/task_pool.rs b/src/libstd/sync/task_pool.rs index 684a46fd6ff5f..06c0c84c41804 100644 --- a/src/libstd/sync/task_pool.rs +++ b/src/libstd/sync/task_pool.rs @@ -20,7 +20,7 @@ use core::prelude::*; use sync::{Arc, Mutex}; use sync::mpsc::{channel, Sender, Receiver}; -use thread::Thread; +use thread; use thunk::Thunk; struct Sentinel<'a> { @@ -112,7 +112,7 @@ impl TaskPool { } fn spawn_in_pool(jobs: Arc>>) { - Thread::spawn(move || { + thread::spawn(move || { // Will spawn a new thread on panic unless it is cancelled. let sentinel = Sentinel::new(&jobs); diff --git a/src/libstd/sys/common/helper_thread.rs b/src/libstd/sys/common/helper_thread.rs index 255f474d4f4af..d3273646b3f4c 100644 --- a/src/libstd/sys/common/helper_thread.rs +++ b/src/libstd/sys/common/helper_thread.rs @@ -30,7 +30,7 @@ use sync::{StaticMutex, StaticCondvar}; use sync::mpsc::{channel, Sender, Receiver}; use sys::helper_signal; -use thread::Thread; +use thread; /// A structure for management of a helper thread. /// @@ -95,7 +95,7 @@ impl Helper { let receive = RaceBox(receive); let t = f(); - Thread::spawn(move || { + thread::spawn(move || { helper(receive.0, rx, t); let _g = self.lock.lock().unwrap(); *self.shutdown.get() = true; diff --git a/src/libstd/sys/common/thread_info.rs b/src/libstd/sys/common/thread_info.rs index 92b936e74f654..65c706033f213 100644 --- a/src/libstd/sys/common/thread_info.rs +++ b/src/libstd/sys/common/thread_info.rs @@ -29,7 +29,7 @@ thread_local! { static THREAD_INFO: RefCell> = RefCell::new(N impl ThreadInfo { fn with(f: F) -> R where F: FnOnce(&mut ThreadInfo) -> R { if THREAD_INFO.state() == State::Destroyed { - panic!("Use of std::thread::Thread::current() is not possible after \ + panic!("Use of std::thread::current() is not possible after \ the thread's local data has been destroyed"); } @@ -63,7 +63,7 @@ pub fn set(stack_bounds: (uint, uint), stack_guard: uint, thread: Thread) { })); } -// a hack to get around privacy restrictions; implemented by `std::thread::Thread` +// a hack to get around privacy restrictions; implemented by `std::thread` pub trait NewThread { fn new(name: Option) -> Self; } diff --git a/src/libstd/sys/common/thread_local.rs b/src/libstd/sys/common/thread_local.rs index 905fac07c5d5d..27b8784e3943a 100644 --- a/src/libstd/sys/common/thread_local.rs +++ b/src/libstd/sys/common/thread_local.rs @@ -24,7 +24,7 @@ //! # Usage //! //! This module should likely not be used directly unless other primitives are -//! being built on. types such as `thread_local::scoped::Key` are likely much +//! being built on. types such as `thread_local::spawn::Key` are likely much //! more useful in practice than this OS-based version which likely requires //! unsafe code to interoperate with. //! diff --git a/src/libstd/thread.rs b/src/libstd/thread.rs index 4f667114d3815..d0fde8344b2b3 100644 --- a/src/libstd/thread.rs +++ b/src/libstd/thread.rs @@ -42,23 +42,23 @@ //! Already-running threads are represented via the `Thread` type, which you can //! get in one of two ways: //! -//! * By spawning a new thread, e.g. using the `Thread::spawn` constructor; -//! * By requesting the current thread, using the `Thread::current` function. +//! * By spawning a new thread, e.g. using the `thread::spawn` constructor; +//! * By requesting the current thread, using the `thread::current` function. //! //! Threads can be named, and provide some built-in support for low-level //! synchronization described below. //! -//! The `Thread::current()` function is available even for threads not spawned +//! The `thread::current()` function is available even for threads not spawned //! by the APIs of this module. //! //! ## Spawning a thread //! -//! A new thread can be spawned using the `Thread::spawn` function: +//! A new thread can be spawned using the `thread::spawn` function: //! //! ```rust -//! use std::thread::Thread; +//! use std::thread; //! -//! Thread::spawn(move || { +//! thread::spawn(move || { //! println!("Hello, World!"); //! // some computation here //! }); @@ -76,14 +76,14 @@ //! For this scenario, use the `scoped` constructor: //! //! ```rust -//! use std::thread::Thread; +//! use std::thread; //! -//! let guard = Thread::scoped(move || { +//! let guard = thread::scoped(move || { //! println!("Hello, World!"); //! // some computation here //! }); //! // do some other work in the meantime -//! let result = guard.join(); +//! let output = guard.join(); //! ``` //! //! The `scoped` function doesn't return a `Thread` directly; instead, @@ -120,10 +120,10 @@ //! Conceptually, each `Thread` handle has an associated token, which is //! initially not present: //! -//! * The `Thread::park()` function blocks the current thread unless or until +//! * The `thread::park()` function blocks the current thread unless or until //! the token is available for its thread handle, at which point It atomically //! consumes the token. It may also return *spuriously*, without consuming the -//! token. `Thread::park_timeout()` does the same, but allows specifying a +//! token. `thread::park_timeout()` does the same, but allows specifying a //! maximum time to block the thread for. //! //! * The `unpark()` method on a `Thread` atomically makes the token available @@ -411,7 +411,7 @@ pub fn panicking() -> bool { // or futuxes, and in either case may allow spurious wakeups. #[stable(feature = "rust1", since = "1.0.0")] pub fn park() { - let thread = Thread::current(); + let thread = current(); let mut guard = thread.inner.lock.lock().unwrap(); while !*guard { guard = thread.inner.cvar.wait(guard).unwrap(); @@ -431,7 +431,7 @@ pub fn park() { /// See the module doc for more detail. #[unstable(feature = "std_misc", reason = "recently introduced, depends on Duration")] pub fn park_timeout(dur: Duration) { - let thread = Thread::current(); + let thread = current(); let mut guard = thread.inner.lock.lock().unwrap(); if !*guard { let (g, _) = thread.inner.cvar.wait_timeout(guard, dur).unwrap(); @@ -512,7 +512,7 @@ impl Thread { #[deprecated(since = "1.0.0", reason = "use module-level free fucntion")] #[unstable(feature = "std_misc", reason = "recently introduced")] pub fn park() { - let thread = Thread::current(); + let thread = current(); let mut guard = thread.inner.lock.lock().unwrap(); while !*guard { guard = thread.inner.cvar.wait(guard).unwrap(); @@ -524,7 +524,7 @@ impl Thread { #[deprecated(since = "1.0.0", reason = "use module-level free fucntion")] #[unstable(feature = "std_misc", reason = "recently introduced")] pub fn park_timeout(dur: Duration) { - let thread = Thread::current(); + let thread = current(); let mut guard = thread.inner.lock.lock().unwrap(); if !*guard { let (g, _) = thread.inner.cvar.wait_timeout(guard, dur).unwrap(); @@ -700,7 +700,7 @@ mod test { use boxed::BoxAny; use result; use std::old_io::{ChanReader, ChanWriter}; - use super::{Thread, Builder}; + use super::{self, Thread, Builder}; use thunk::Thunk; use time::Duration; @@ -709,22 +709,22 @@ mod test { #[test] fn test_unnamed_thread() { - Thread::scoped(move|| { - assert!(Thread::current().name().is_none()); + thread::spawn(move|| { + assert!(thread::current().name().is_none()); }).join().ok().unwrap(); } #[test] fn test_named_thread() { Builder::new().name("ada lovelace".to_string()).scoped(move|| { - assert!(Thread::current().name().unwrap() == "ada lovelace".to_string()); + assert!(thread::current().name().unwrap() == "ada lovelace".to_string()); }).join().ok().unwrap(); } #[test] fn test_run_basic() { let (tx, rx) = channel(); - Thread::spawn(move|| { + thread::spawn(move|| { tx.send(()).unwrap(); }); rx.recv().unwrap(); @@ -732,7 +732,7 @@ mod test { #[test] fn test_join_success() { - match Thread::scoped(move|| -> String { + match thread::spawn(move|| -> String { "Success!".to_string() }).join().as_ref().map(|s| &**s) { result::Result::Ok("Success!") => (), @@ -742,7 +742,7 @@ mod test { #[test] fn test_join_panic() { - match Thread::scoped(move|| { + match thread::spawn(move|| { panic!() }).join() { result::Result::Err(_) => (), @@ -750,6 +750,26 @@ mod test { } } + #[test] + fn test_scoped_success() { + let res = thread::scoped(move|| -> String { + "Success!".to_string() + }).join(); + assert!(res == "Success!"); + } + + #[test] + #[should_fail] + fn test_scoped_panic() { + thread::scoped(|| panic!()).join(); + } + + #[test] + #[should_fail] + fn test_scoped_implicit_panic() { + thread::scoped(|| panic!()); + } + #[test] fn test_spawn_sched() { use clone::Clone; @@ -758,7 +778,7 @@ mod test { fn f(i: int, tx: Sender<()>) { let tx = tx.clone(); - Thread::spawn(move|| { + thread::spawn(move|| { if i == 0 { tx.send(()).unwrap(); } else { @@ -775,8 +795,8 @@ mod test { fn test_spawn_sched_childs_on_default_sched() { let (tx, rx) = channel(); - Thread::spawn(move|| { - Thread::spawn(move|| { + thread::spawn(move|| { + thread::spawn(move|| { tx.send(()).unwrap(); }); }); @@ -802,14 +822,14 @@ mod test { #[test] fn test_avoid_copying_the_body_spawn() { avoid_copying_the_body(|v| { - Thread::spawn(move || v.invoke(())); + thread::spawn(move || v.invoke(())); }); } #[test] fn test_avoid_copying_the_body_thread_spawn() { avoid_copying_the_body(|f| { - Thread::spawn(move|| { + thread::spawn(move|| { f.invoke(()); }); }) @@ -818,7 +838,7 @@ mod test { #[test] fn test_avoid_copying_the_body_join() { avoid_copying_the_body(|f| { - let _ = Thread::scoped(move|| { + let _ = thread::spawn(move|| { f.invoke(()) }).join(); }) @@ -834,21 +854,21 @@ mod test { fn child_no(x: uint) -> Thunk { return Thunk::new(move|| { if x < GENERATIONS { - Thread::spawn(move|| child_no(x+1).invoke(())); + thread::spawn(move|| child_no(x+1).invoke(())); } }); } - Thread::spawn(|| child_no(0).invoke(())); + thread::spawn(|| child_no(0).invoke(())); } #[test] fn test_simple_newsched_spawn() { - Thread::spawn(move || {}); + thread::spawn(move || {}); } #[test] fn test_try_panic_message_static_str() { - match Thread::scoped(move|| { + match thread::spawn(move|| { panic!("static string"); }).join() { Err(e) => { @@ -862,7 +882,7 @@ mod test { #[test] fn test_try_panic_message_owned_str() { - match Thread::scoped(move|| { + match thread::spawn(move|| { panic!("owned string".to_string()); }).join() { Err(e) => { @@ -876,7 +896,7 @@ mod test { #[test] fn test_try_panic_message_any() { - match Thread::scoped(move|| { + match thread::spawn(move|| { panic!(box 413u16 as Box); }).join() { Err(e) => { @@ -894,7 +914,7 @@ mod test { fn test_try_panic_message_unit_struct() { struct Juju; - match Thread::scoped(move|| { + match thread::spawn(move|| { panic!(Juju) }).join() { Err(ref e) if e.is::() => {} @@ -920,15 +940,15 @@ mod test { #[test] fn test_park_timeout_unpark_before() { for _ in 0..10 { - Thread::current().unpark(); - Thread::park_timeout(Duration::seconds(10_000_000)); + thread::current().unpark(); + thread::park_timeout(Duration::seconds(10_000_000)); } } #[test] fn test_park_timeout_unpark_not_called() { for _ in 0..10 { - Thread::park_timeout(Duration::milliseconds(10)); + thread::park_timeout(Duration::milliseconds(10)); } } @@ -937,14 +957,14 @@ mod test { use std::old_io; for _ in 0..10 { - let th = Thread::current(); + let th = thread::current(); - let _guard = Thread::scoped(move || { + let _guard = thread::spawn(move || { old_io::timer::sleep(Duration::milliseconds(50)); th.unpark(); }); - Thread::park_timeout(Duration::seconds(10_000_000)); + thread::park_timeout(Duration::seconds(10_000_000)); } } diff --git a/src/libstd/thread_local/mod.rs b/src/libstd/thread_local/mod.rs index eab9cd84539ed..2ed296e081c90 100644 --- a/src/libstd/thread_local/mod.rs +++ b/src/libstd/thread_local/mod.rs @@ -72,7 +72,7 @@ pub mod __impl { /// /// ``` /// use std::cell::RefCell; -/// use std::thread::Thread; +/// use std::thread; /// /// thread_local!(static FOO: RefCell = RefCell::new(1)); /// @@ -82,7 +82,7 @@ pub mod __impl { /// }); /// /// // each thread starts out with the initial value of 1 -/// Thread::spawn(move|| { +/// thread::spawn(move|| { /// FOO.with(|f| { /// assert_eq!(*f.borrow(), 1); /// *f.borrow_mut() = 3; @@ -548,7 +548,7 @@ mod tests { use sync::mpsc::{channel, Sender}; use cell::UnsafeCell; use super::State; - use thread::Thread; + use thread; struct Foo(Sender<()>); @@ -568,7 +568,7 @@ mod tests { *f.get() = 2; }); let (tx, rx) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { FOO.with(|f| unsafe { assert_eq!(*f.get(), 1); }); @@ -595,7 +595,7 @@ mod tests { } thread_local!(static FOO: Foo = foo()); - Thread::scoped(|| { + thread::spawn(|| { assert!(FOO.state() == State::Uninitialized); FOO.with(|_| { assert!(FOO.state() == State::Valid); @@ -611,7 +611,7 @@ mod tests { }); let (tx, rx) = channel(); - let _t = Thread::spawn(move|| unsafe { + let _t = thread::spawn(move|| unsafe { let mut tx = Some(tx); FOO.with(|f| { *f.get() = Some(Foo(tx.take().unwrap())); @@ -659,7 +659,7 @@ mod tests { } } - Thread::scoped(move|| { + thread::spawn(move|| { drop(S1); }).join().ok().unwrap(); } @@ -677,7 +677,7 @@ mod tests { } } - Thread::scoped(move|| unsafe { + thread::spawn(move|| unsafe { K1.with(|s| *s.get() = Some(S1)); }).join().ok().unwrap(); } @@ -704,7 +704,7 @@ mod tests { } let (tx, rx) = channel(); - let _t = Thread::spawn(move|| unsafe { + let _t = thread::spawn(move|| unsafe { let mut tx = Some(tx); K1.with(|s| *s.get() = Some(S1(tx.take().unwrap()))); }); diff --git a/src/libstd/thread_local/scoped.rs b/src/libstd/thread_local/scoped.rs index 01220e7bc1fe1..e4633ea0f76f0 100644 --- a/src/libstd/thread_local/scoped.rs +++ b/src/libstd/thread_local/scoped.rs @@ -84,7 +84,7 @@ macro_rules! __scoped_thread_local_inner { target_os = "openbsd", target_arch = "aarch64")), thread_local)] - static $name: ::std::thread_local::scoped::Key<$t> = + static $name: ::std::thread_local::spawn::Key<$t> = __scoped_thread_local_inner!($t); ); (pub static $name:ident: $t:ty) => ( @@ -94,11 +94,11 @@ macro_rules! __scoped_thread_local_inner { target_os = "openbsd", target_arch = "aarch64")), thread_local)] - pub static $name: ::std::thread_local::scoped::Key<$t> = + pub static $name: ::std::thread_local::spawn::Key<$t> = __scoped_thread_local_inner!($t); ); ($t:ty) => ({ - use std::thread_local::scoped::Key as __Key; + use std::thread_local::spawn::Key as __Key; #[cfg(not(any(windows, target_os = "android", @@ -106,7 +106,7 @@ macro_rules! __scoped_thread_local_inner { target_os = "openbsd", target_arch = "aarch64")))] const _INIT: __Key<$t> = __Key { - inner: ::std::thread_local::scoped::__impl::KeyInner { + inner: ::std::thread_local::spawn::__impl::KeyInner { inner: ::std::cell::UnsafeCell { value: 0 as *mut _ }, } }; @@ -117,8 +117,8 @@ macro_rules! __scoped_thread_local_inner { target_os = "openbsd", target_arch = "aarch64"))] const _INIT: __Key<$t> = __Key { - inner: ::std::thread_local::scoped::__impl::KeyInner { - inner: ::std::thread_local::scoped::__impl::OS_INIT, + inner: ::std::thread_local::spawn::__impl::KeyInner { + inner: ::std::thread_local::spawn::__impl::OS_INIT, marker: ::std::marker::InvariantType, } }; diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 860ce209d451f..5e1b8a3fc90ef 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -879,7 +879,7 @@ pub fn run_test(opts: &TestOpts, monitor_ch: Sender, nocapture: bool, testfn: Thunk) { - Thread::spawn(move || { + thread::spawn(move || { let (tx, rx) = channel(); let mut reader = ChanReader::new(rx); let stdout = ChanWriter::new(tx.clone()); diff --git a/src/test/auxiliary/cci_capture_clause.rs b/src/test/auxiliary/cci_capture_clause.rs index 673c38697b79c..29a6ce5965811 100644 --- a/src/test/auxiliary/cci_capture_clause.rs +++ b/src/test/auxiliary/cci_capture_clause.rs @@ -8,12 +8,12 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::thread::Thread; +use std::thread; use std::sync::mpsc::{Receiver, channel}; pub fn foo(x: T) -> Receiver { let (tx, rx) = channel(); - Thread::spawn(move|| { + thread::spawn(move|| { tx.send(x.clone()); }); rx diff --git a/src/test/bench/msgsend-pipes-shared.rs b/src/test/bench/msgsend-pipes-shared.rs index 4e9c2fe99bd4a..3a8d65d73c962 100644 --- a/src/test/bench/msgsend-pipes-shared.rs +++ b/src/test/bench/msgsend-pipes-shared.rs @@ -21,7 +21,7 @@ use std::sync::mpsc::{channel, Sender, Receiver}; use std::os; use std::env; -use std::thread::Thread; +use std::thread; use std::time::Duration; fn move_out(_x: T) {} @@ -64,7 +64,7 @@ fn run(args: &[String]) { let mut worker_results = Vec::new(); for _ in 0u..workers { let to_child = to_child.clone(); - worker_results.push(Thread::scoped(move|| { + worker_results.push(thread::spawn(move|| { for _ in 0u..size / workers { //println!("worker {}: sending {} bytes", i, num_bytes); to_child.send(request::bytes(num_bytes)).unwrap(); @@ -72,7 +72,7 @@ fn run(args: &[String]) { //println!("worker {} exiting", i); })); } - Thread::spawn(move|| { + thread::spawn(move|| { server(&from_parent, &to_parent); }); diff --git a/src/test/bench/msgsend-pipes.rs b/src/test/bench/msgsend-pipes.rs index 2530e8bd90707..3f05b46aa71ea 100644 --- a/src/test/bench/msgsend-pipes.rs +++ b/src/test/bench/msgsend-pipes.rs @@ -17,7 +17,7 @@ use std::sync::mpsc::{channel, Sender, Receiver}; use std::os; use std::env; -use std::thread::Thread; +use std::thread; use std::time::Duration; enum request { @@ -57,7 +57,7 @@ fn run(args: &[String]) { let mut worker_results = Vec::new(); let from_parent = if workers == 1 { let (to_child, from_parent) = channel(); - worker_results.push(Thread::scoped(move|| { + worker_results.push(thread::spawn(move|| { for _ in 0u..size / workers { //println!("worker {}: sending {} bytes", i, num_bytes); to_child.send(request::bytes(num_bytes)); @@ -69,7 +69,7 @@ fn run(args: &[String]) { let (to_child, from_parent) = channel(); for _ in 0u..workers { let to_child = to_child.clone(); - worker_results.push(Thread::scoped(move|| { + worker_results.push(thread::spawn(move|| { for _ in 0u..size / workers { //println!("worker {}: sending {} bytes", i, num_bytes); to_child.send(request::bytes(num_bytes)); @@ -79,7 +79,7 @@ fn run(args: &[String]) { } from_parent }; - Thread::spawn(move|| { + thread::spawn(move|| { server(&from_parent, &to_parent); }); diff --git a/src/test/bench/rt-messaging-ping-pong.rs b/src/test/bench/rt-messaging-ping-pong.rs index e4e8b4a6e6e1e..1ecd983a5c50a 100644 --- a/src/test/bench/rt-messaging-ping-pong.rs +++ b/src/test/bench/rt-messaging-ping-pong.rs @@ -19,7 +19,7 @@ use std::sync::mpsc::channel; use std::os; -use std::thread::Thread; +use std::thread; // This is a simple bench that creates M pairs of tasks. These // tasks ping-pong back and forth over a pair of streams. This is a @@ -35,7 +35,7 @@ fn ping_pong_bench(n: uint, m: uint) { // Create a channel: B->A let (btx, brx) = channel(); - let guard_a = Thread::scoped(move|| { + let guard_a = thread::spawn(move|| { let (tx, rx) = (atx, brx); for _ in 0..n { tx.send(()).unwrap(); @@ -43,7 +43,7 @@ fn ping_pong_bench(n: uint, m: uint) { } }); - let guard_b = Thread::scoped(move|| { + let guard_b = thread::spawn(move|| { let (tx, rx) = (btx, arx); for _ in 0..n { rx.recv().unwrap(); diff --git a/src/test/bench/rt-parfib.rs b/src/test/bench/rt-parfib.rs index 13b8a5ca763ad..4ab937d47e307 100644 --- a/src/test/bench/rt-parfib.rs +++ b/src/test/bench/rt-parfib.rs @@ -10,7 +10,7 @@ use std::sync::mpsc::channel; use std::os; -use std::thread::Thread; +use std::thread; // A simple implementation of parfib. One subtree is found in a new // task and communicated over a oneshot pipe, the other is found @@ -22,7 +22,7 @@ fn parfib(n: uint) -> uint { } let (tx, rx) = channel(); - Thread::spawn(move|| { + thread::spawn(move|| { tx.send(parfib(n-1)).unwrap(); }); let m2 = parfib(n-2); diff --git a/src/test/bench/shootout-binarytrees.rs b/src/test/bench/shootout-binarytrees.rs index 0311a1ac7c4e1..b10d22e5d687a 100644 --- a/src/test/bench/shootout-binarytrees.rs +++ b/src/test/bench/shootout-binarytrees.rs @@ -111,7 +111,7 @@ fn main() { let messages = range_step(min_depth, max_depth + 1, 2).map(|depth| { use std::num::Int; let iterations = 2.pow((max_depth - depth + min_depth) as usize); - Thread::scoped(move || inner(depth, iterations)) + thread::spawn(move || inner(depth, iterations)) }).collect::>(); for message in messages { diff --git a/src/test/bench/shootout-chameneos-redux.rs b/src/test/bench/shootout-chameneos-redux.rs index 628206986c518..8fc6209836124 100644 --- a/src/test/bench/shootout-chameneos-redux.rs +++ b/src/test/bench/shootout-chameneos-redux.rs @@ -43,7 +43,7 @@ use self::Color::{Red, Yellow, Blue}; use std::sync::mpsc::{channel, Sender, Receiver}; use std::fmt; -use std::thread::Thread; +use std::thread; fn print_complements() { let all = [Blue, Red, Yellow]; @@ -187,7 +187,7 @@ fn rendezvous(nn: uint, set: Vec) { let to_rendezvous = to_rendezvous.clone(); let to_rendezvous_log = to_rendezvous_log.clone(); let (to_creature, from_rendezvous) = channel(); - Thread::spawn(move|| { + thread::spawn(move|| { creature(ii, col, from_rendezvous, diff --git a/src/test/bench/shootout-fannkuch-redux.rs b/src/test/bench/shootout-fannkuch-redux.rs index 92e1bc1a922c2..8509a86e47dd8 100644 --- a/src/test/bench/shootout-fannkuch-redux.rs +++ b/src/test/bench/shootout-fannkuch-redux.rs @@ -39,7 +39,7 @@ // OF THE POSSIBILITY OF SUCH DAMAGE. use std::{cmp, iter, mem}; -use std::thread::Thread; +use std::thread; fn rotate(x: &mut [i32]) { let mut prev = x[0]; @@ -164,7 +164,7 @@ fn fannkuch(n: i32) -> (i32, i32) { for (_, j) in (0..N).zip(iter::count(0, k)) { let max = cmp::min(j+k, perm.max()); - futures.push(Thread::scoped(move|| { + futures.push(thread::spawn(move|| { work(perm, j as uint, max as uint) })) } diff --git a/src/test/bench/shootout-k-nucleotide-pipes.rs b/src/test/bench/shootout-k-nucleotide-pipes.rs index 3c96878179f3a..4d6ef3d533e3f 100644 --- a/src/test/bench/shootout-k-nucleotide-pipes.rs +++ b/src/test/bench/shootout-k-nucleotide-pipes.rs @@ -24,7 +24,7 @@ use std::option; use std::os; use std::env; use std::sync::mpsc::{channel, Sender, Receiver}; -use std::thread::Thread; +use std::thread; fn f64_cmp(x: f64, y: f64) -> Ordering { // arbitrarily decide that NaNs are larger than everything. @@ -172,7 +172,7 @@ fn main() { let (to_child, from_parent) = channel(); - Thread::spawn(move|| { + thread::spawn(move|| { make_sequence_processor(sz, &from_parent, &to_parent_); }); diff --git a/src/test/bench/shootout-k-nucleotide.rs b/src/test/bench/shootout-k-nucleotide.rs index ca920b2fa821c..e6beb952603bd 100644 --- a/src/test/bench/shootout-k-nucleotide.rs +++ b/src/test/bench/shootout-k-nucleotide.rs @@ -45,7 +45,7 @@ use std::ascii::OwnedAsciiExt; use std::slice; use std::sync::Arc; -use std::thread::Thread; +use std::thread; static TABLE: [u8;4] = [ 'A' as u8, 'C' as u8, 'G' as u8, 'T' as u8 ]; static TABLE_SIZE: uint = 2 << 16; @@ -303,11 +303,11 @@ fn main() { let nb_freqs: Vec<_> = (1u..3).map(|i| { let input = input.clone(); - (i, Thread::scoped(move|| generate_frequencies(&input, i))) + (i, thread::spawn(move|| generate_frequencies(&input, i))) }).collect(); let occ_freqs: Vec<_> = OCCURRENCES.iter().map(|&occ| { let input = input.clone(); - Thread::scoped(move|| generate_frequencies(&input, occ.len())) + thread::spawn(move|| generate_frequencies(&input, occ.len())) }).collect(); for (i, freq) in nb_freqs { diff --git a/src/test/bench/shootout-mandelbrot.rs b/src/test/bench/shootout-mandelbrot.rs index e2d51fbf4111d..fa5ddb1567a6a 100644 --- a/src/test/bench/shootout-mandelbrot.rs +++ b/src/test/bench/shootout-mandelbrot.rs @@ -46,7 +46,7 @@ use std::old_io; use std::os; use std::simd::f64x2; use std::sync::Arc; -use std::thread::Thread; +use std::thread; const ITER: usize = 50; const LIMIT: f64 = 2.0; @@ -81,7 +81,7 @@ fn mandelbrot(w: usize, mut out: W) -> old_io::IoResult<()> { let mut precalc_i = Vec::with_capacity(h); let precalc_futures = (0..WORKERS).map(|i| { - Thread::scoped(move|| { + thread::spawn(move|| { let mut rs = Vec::with_capacity(w / WORKERS); let mut is = Vec::with_capacity(w / WORKERS); @@ -122,7 +122,7 @@ fn mandelbrot(w: usize, mut out: W) -> old_io::IoResult<()> { let vec_init_r = arc_init_r.clone(); let vec_init_i = arc_init_i.clone(); - Thread::scoped(move|| { + thread::spawn(move|| { let mut res: Vec = Vec::with_capacity((chunk_size * w) / 8); let init_r_slice = vec_init_r; diff --git a/src/test/bench/shootout-meteor.rs b/src/test/bench/shootout-meteor.rs index d061403d5901d..a9c4bb99a0ed1 100644 --- a/src/test/bench/shootout-meteor.rs +++ b/src/test/bench/shootout-meteor.rs @@ -43,7 +43,7 @@ use std::iter::repeat; use std::sync::Arc; use std::sync::mpsc::channel; -use std::thread::Thread; +use std::thread; // // Utilities. @@ -317,7 +317,7 @@ fn par_search(masks: Vec>>) -> Data { let masks = masks.clone(); let tx = tx.clone(); let m = *m; - Thread::spawn(move|| { + thread::spawn(move|| { let mut data = Data::new(); search(&*masks, m, 1, List::Cons(m, &List::Nil), &mut data); tx.send(data).unwrap(); diff --git a/src/test/bench/shootout-pfib.rs b/src/test/bench/shootout-pfib.rs index 9abc808f88770..97e5533f2de48 100644 --- a/src/test/bench/shootout-pfib.rs +++ b/src/test/bench/shootout-pfib.rs @@ -24,7 +24,7 @@ use std::sync::mpsc::{channel, Sender}; use std::os; use std::env; use std::result::Result::{Ok, Err}; -use std::thread::Thread; +use std::thread; use std::time::Duration; fn fib(n: int) -> int { @@ -36,15 +36,15 @@ fn fib(n: int) -> int { } else { let (tx1, rx) = channel(); let tx2 = tx1.clone(); - Thread::spawn(move|| pfib(&tx2, n - 1)); + thread::spawn(move|| pfib(&tx2, n - 1)); let tx2 = tx1.clone(); - Thread::spawn(move|| pfib(&tx2, n - 2)); + thread::spawn(move|| pfib(&tx2, n - 2)); tx.send(rx.recv().unwrap() + rx.recv().unwrap()); } } let (tx, rx) = channel(); - Thread::spawn(move|| pfib(&tx, n) ); + thread::spawn(move|| pfib(&tx, n) ); rx.recv().unwrap() } @@ -79,7 +79,7 @@ fn stress_task(id: int) { fn stress(num_tasks: int) { let mut results = Vec::new(); for i in 0..num_tasks { - results.push(Thread::scoped(move|| { + results.push(thread::spawn(move|| { stress_task(i); })); } diff --git a/src/test/bench/shootout-reverse-complement.rs b/src/test/bench/shootout-reverse-complement.rs index 944383199543f..3d8b6e82848b9 100644 --- a/src/test/bench/shootout-reverse-complement.rs +++ b/src/test/bench/shootout-reverse-complement.rs @@ -47,7 +47,7 @@ extern crate libc; use std::old_io::stdio::{stdin_raw, stdout_raw}; use std::old_io::{IoResult, EndOfFile}; use std::ptr::{copy_memory, Unique}; -use std::thread::Thread; +use std::thread; struct Tables { table8: [u8;1 << 8], @@ -241,7 +241,7 @@ fn parallel<'a, I, T, F>(iter: I, f: F) // boundary. let f = Racy(&f as *const F as *const uint); let raw = Racy(chunk.repr()); - Thread::scoped(move|| { + thread::spawn(move|| { let f = f.0 as *const F; unsafe { (*f)(mem::transmute(raw.0)) } }) diff --git a/src/test/bench/shootout-spectralnorm.rs b/src/test/bench/shootout-spectralnorm.rs index 8356df8d8a184..a8a90120ebba5 100644 --- a/src/test/bench/shootout-spectralnorm.rs +++ b/src/test/bench/shootout-spectralnorm.rs @@ -44,7 +44,7 @@ #![feature(unboxed_closures)] use std::iter::{repeat, AdditiveIterator}; -use std::thread::Thread; +use std::thread; use std::mem; use std::num::Float; use std::os; @@ -129,7 +129,7 @@ fn parallel(v: &mut [T], f: F) // boundary. let f = Racy(&f as *const _ as *const uint); let raw = Racy(chunk.repr()); - Thread::scoped(move|| { + thread::spawn(move|| { let f = f.0 as *const F; unsafe { (*f)(i * size, mem::transmute(raw.0)) } }) diff --git a/src/test/bench/shootout-threadring.rs b/src/test/bench/shootout-threadring.rs index 8614f94da89ea..29b9938b77b33 100644 --- a/src/test/bench/shootout-threadring.rs +++ b/src/test/bench/shootout-threadring.rs @@ -39,7 +39,7 @@ // OF THE POSSIBILITY OF SUCH DAMAGE. use std::sync::mpsc::{channel, Sender, Receiver}; -use std::thread::Thread; +use std::thread; fn start(n_tasks: i32, token: i32) { let (tx, mut rx) = channel(); @@ -48,9 +48,9 @@ fn start(n_tasks: i32, token: i32) { for i in 2 .. n_tasks + 1 { let (tx, next_rx) = channel(); let cur_rx = std::mem::replace(&mut rx, next_rx); - guards.push(Thread::scoped(move|| roundtrip(i, tx, cur_rx))); + guards.push(thread::spawn(move|| roundtrip(i, tx, cur_rx))); } - let guard = Thread::scoped(move|| roundtrip(1, tx, rx)); + let guard = thread::spawn(move|| roundtrip(1, tx, rx)); } fn roundtrip(id: i32, tx: Sender, rx: Receiver) { diff --git a/src/test/bench/task-perf-alloc-unwind.rs b/src/test/bench/task-perf-alloc-unwind.rs index c45efe5f54b2c..6b412c47cd7f8 100644 --- a/src/test/bench/task-perf-alloc-unwind.rs +++ b/src/test/bench/task-perf-alloc-unwind.rs @@ -11,7 +11,7 @@ #![feature(unsafe_destructor, box_syntax)] use std::env; -use std::thread::Thread; +use std::thread; use std::time::Duration; #[derive(Clone)] @@ -32,7 +32,7 @@ fn main() { fn run(repeat: int, depth: int) { for _ in 0..repeat { let dur = Duration::span(|| { - let _ = Thread::scoped(move|| { + let _ = thread::spawn(move|| { recurse_or_panic(depth, None) }).join(); }); diff --git a/src/test/bench/task-perf-jargon-metal-smoke.rs b/src/test/bench/task-perf-jargon-metal-smoke.rs index 9edb4201098d6..923be213fd397 100644 --- a/src/test/bench/task-perf-jargon-metal-smoke.rs +++ b/src/test/bench/task-perf-jargon-metal-smoke.rs @@ -20,15 +20,15 @@ use std::sync::mpsc::{channel, Sender}; use std::os; use std::env; -use std::thread::Thread; +use std::thread; fn child_generation(gens_left: uint, tx: Sender<()>) { // This used to be O(n^2) in the number of generations that ever existed. // With this code, only as many generations are alive at a time as tasks // alive at a time, - Thread::spawn(move|| { + thread::spawn(move|| { if gens_left & 1 == 1 { - Thread::yield_now(); // shake things up a bit + thread::yield_now(); // shake things up a bit } if gens_left > 0 { child_generation(gens_left - 1, tx); // recurse diff --git a/src/test/bench/task-perf-spawnalot.rs b/src/test/bench/task-perf-spawnalot.rs index 279b3fa432a3c..d10d9cb460f34 100644 --- a/src/test/bench/task-perf-spawnalot.rs +++ b/src/test/bench/task-perf-spawnalot.rs @@ -10,12 +10,12 @@ use std::os; use std::env; -use std::thread::Thread; +use std::thread; fn f(n: uint) { let mut i = 0u; while i < n { - let _ = Thread::scoped(move|| g()).join(); + let _ = thread::spawn(move|| g()).join(); i += 1u; } } @@ -33,5 +33,5 @@ fn main() { }; let n = args[1].parse().unwrap(); let mut i = 0u; - while i < n { Thread::spawn(move|| f(n) ); i += 1u; } + while i < n { thread::spawn(move|| f(n) ); i += 1u; } } diff --git a/src/test/compile-fail/borrowck-loan-blocks-move-cc.rs b/src/test/compile-fail/borrowck-loan-blocks-move-cc.rs index 980c498e39b47..7f676f5166f7f 100644 --- a/src/test/compile-fail/borrowck-loan-blocks-move-cc.rs +++ b/src/test/compile-fail/borrowck-loan-blocks-move-cc.rs @@ -10,7 +10,7 @@ #![feature(box_syntax)] -use std::thread::Thread; +use std::thread; fn borrow(v: &isize, f: F) where F: FnOnce(&isize) { f(v); @@ -19,7 +19,7 @@ fn borrow(v: &isize, f: F) where F: FnOnce(&isize) { fn box_imm() { let v = box 3; let _w = &v; - Thread::spawn(move|| { + thread::spawn(move|| { println!("v={}", *v); //~^ ERROR cannot move `v` into closure }); @@ -28,7 +28,7 @@ fn box_imm() { fn box_imm_explicit() { let v = box 3; let _w = &v; - Thread::spawn(move|| { + thread::spawn(move|| { println!("v={}", *v); //~^ ERROR cannot move }); diff --git a/src/test/compile-fail/borrowck-multiple-captures.rs b/src/test/compile-fail/borrowck-multiple-captures.rs index 94e213ae1ae5b..9db05d76284e8 100644 --- a/src/test/compile-fail/borrowck-multiple-captures.rs +++ b/src/test/compile-fail/borrowck-multiple-captures.rs @@ -10,7 +10,7 @@ #![feature(box_syntax)] -use std::thread::Thread; +use std::thread; fn borrow(_: &T) { } @@ -19,7 +19,7 @@ fn different_vars_after_borrows() { let p1 = &x1; let x2 = box 2; let p2 = &x2; - Thread::spawn(move|| { + thread::spawn(move|| { drop(x1); //~ ERROR cannot move `x1` into closure because it is borrowed drop(x2); //~ ERROR cannot move `x2` into closure because it is borrowed }); @@ -32,7 +32,7 @@ fn different_vars_after_moves() { drop(x1); let x2 = box 2; drop(x2); - Thread::spawn(move|| { + thread::spawn(move|| { drop(x1); //~ ERROR capture of moved value: `x1` drop(x2); //~ ERROR capture of moved value: `x2` }); @@ -41,7 +41,7 @@ fn different_vars_after_moves() { fn same_var_after_borrow() { let x = box 1; let p = &x; - Thread::spawn(move|| { + thread::spawn(move|| { drop(x); //~ ERROR cannot move `x` into closure because it is borrowed drop(x); //~ ERROR use of moved value: `x` }); @@ -51,7 +51,7 @@ fn same_var_after_borrow() { fn same_var_after_move() { let x = box 1; drop(x); - Thread::spawn(move|| { + thread::spawn(move|| { drop(x); //~ ERROR capture of moved value: `x` drop(x); //~ ERROR use of moved value: `x` }); diff --git a/src/test/compile-fail/issue-12041.rs b/src/test/compile-fail/issue-12041.rs index 236142a691921..735f529277c36 100644 --- a/src/test/compile-fail/issue-12041.rs +++ b/src/test/compile-fail/issue-12041.rs @@ -9,11 +9,11 @@ // except according to those terms. use std::sync::mpsc::channel; -use std::thread::Thread; +use std::thread; fn main() { let (tx, rx) = channel(); - let _t = Thread::spawn(move|| -> () { + let _t = thread::spawn(move|| -> () { loop { let tx = tx; //~^ ERROR: use of moved value: `tx` diff --git a/src/test/compile-fail/issue-8460-const.rs b/src/test/compile-fail/issue-8460-const.rs index 01bed69fb1de9..4e44b4dcdce3e 100644 --- a/src/test/compile-fail/issue-8460-const.rs +++ b/src/test/compile-fail/issue-8460-const.rs @@ -9,47 +9,47 @@ // except according to those terms. use std::{int, i8, i16, i32, i64}; -use std::thread::Thread; +use std::thread; fn main() { - assert!(Thread::scoped(move|| int::MIN / -1).join().is_err()); + assert!(thread::spawn(move|| int::MIN / -1).join().is_err()); //~^ ERROR attempted to divide with overflow in a constant expression - assert!(Thread::scoped(move|| i8::MIN / -1).join().is_err()); + assert!(thread::spawn(move|| i8::MIN / -1).join().is_err()); //~^ ERROR attempted to divide with overflow in a constant expression - assert!(Thread::scoped(move|| i16::MIN / -1).join().is_err()); + assert!(thread::spawn(move|| i16::MIN / -1).join().is_err()); //~^ ERROR attempted to divide with overflow in a constant expression - assert!(Thread::scoped(move|| i32::MIN / -1).join().is_err()); + assert!(thread::spawn(move|| i32::MIN / -1).join().is_err()); //~^ ERROR attempted to divide with overflow in a constant expression - assert!(Thread::scoped(move|| i64::MIN / -1).join().is_err()); + assert!(thread::spawn(move|| i64::MIN / -1).join().is_err()); //~^ ERROR attempted to divide with overflow in a constant expression - assert!(Thread::scoped(move|| 1is / 0).join().is_err()); + assert!(thread::spawn(move|| 1is / 0).join().is_err()); //~^ ERROR attempted to divide by zero in a constant expression - assert!(Thread::scoped(move|| 1i8 / 0).join().is_err()); + assert!(thread::spawn(move|| 1i8 / 0).join().is_err()); //~^ ERROR attempted to divide by zero in a constant expression - assert!(Thread::scoped(move|| 1i16 / 0).join().is_err()); + assert!(thread::spawn(move|| 1i16 / 0).join().is_err()); //~^ ERROR attempted to divide by zero in a constant expression - assert!(Thread::scoped(move|| 1i32 / 0).join().is_err()); + assert!(thread::spawn(move|| 1i32 / 0).join().is_err()); //~^ ERROR attempted to divide by zero in a constant expression - assert!(Thread::scoped(move|| 1i64 / 0).join().is_err()); + assert!(thread::spawn(move|| 1i64 / 0).join().is_err()); //~^ ERROR attempted to divide by zero in a constant expression - assert!(Thread::scoped(move|| int::MIN % -1).join().is_err()); + assert!(thread::spawn(move|| int::MIN % -1).join().is_err()); //~^ ERROR attempted remainder with overflow in a constant expression - assert!(Thread::scoped(move|| i8::MIN % -1).join().is_err()); + assert!(thread::spawn(move|| i8::MIN % -1).join().is_err()); //~^ ERROR attempted remainder with overflow in a constant expression - assert!(Thread::scoped(move|| i16::MIN % -1).join().is_err()); + assert!(thread::spawn(move|| i16::MIN % -1).join().is_err()); //~^ ERROR attempted remainder with overflow in a constant expression - assert!(Thread::scoped(move|| i32::MIN % -1).join().is_err()); + assert!(thread::spawn(move|| i32::MIN % -1).join().is_err()); //~^ ERROR attempted remainder with overflow in a constant expression - assert!(Thread::scoped(move|| i64::MIN % -1).join().is_err()); + assert!(thread::spawn(move|| i64::MIN % -1).join().is_err()); //~^ ERROR attempted remainder with overflow in a constant expression - assert!(Thread::scoped(move|| 1is % 0).join().is_err()); + assert!(thread::spawn(move|| 1is % 0).join().is_err()); //~^ ERROR attempted remainder with a divisor of zero in a constant expression - assert!(Thread::scoped(move|| 1i8 % 0).join().is_err()); + assert!(thread::spawn(move|| 1i8 % 0).join().is_err()); //~^ ERROR attempted remainder with a divisor of zero in a constant expression - assert!(Thread::scoped(move|| 1i16 % 0).join().is_err()); + assert!(thread::spawn(move|| 1i16 % 0).join().is_err()); //~^ ERROR attempted remainder with a divisor of zero in a constant expression - assert!(Thread::scoped(move|| 1i32 % 0).join().is_err()); + assert!(thread::spawn(move|| 1i32 % 0).join().is_err()); //~^ ERROR attempted remainder with a divisor of zero in a constant expression - assert!(Thread::scoped(move|| 1i64 % 0).join().is_err()); + assert!(thread::spawn(move|| 1i64 % 0).join().is_err()); //~^ ERROR attempted remainder with a divisor of zero in a constant expression } diff --git a/src/test/compile-fail/missing-stability.rs b/src/test/compile-fail/missing-stability.rs index 14dd983161b4a..cf7a8378b9a9a 100644 --- a/src/test/compile-fail/missing-stability.rs +++ b/src/test/compile-fail/missing-stability.rs @@ -30,4 +30,4 @@ pub mod bar { // #[stable] is not inherited pub fn unmarked() {} //~^ ERROR This node does not have a stability attribute -} \ No newline at end of file +} diff --git a/src/test/compile-fail/moves-based-on-type-capture-clause-bad.rs b/src/test/compile-fail/moves-based-on-type-capture-clause-bad.rs index dc90994fcc102..32fa773ec8079 100644 --- a/src/test/compile-fail/moves-based-on-type-capture-clause-bad.rs +++ b/src/test/compile-fail/moves-based-on-type-capture-clause-bad.rs @@ -8,11 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::thread::Thread; +use std::thread; fn main() { let x = "Hello world!".to_string(); - Thread::spawn(move|| { + thread::spawn(move|| { println!("{}", x); }); println!("{}", x); //~ ERROR use of moved value diff --git a/src/test/compile-fail/no-capture-arc.rs b/src/test/compile-fail/no-capture-arc.rs index 939d7c7a5348b..7b7b3c414dded 100644 --- a/src/test/compile-fail/no-capture-arc.rs +++ b/src/test/compile-fail/no-capture-arc.rs @@ -11,13 +11,13 @@ // error-pattern: use of moved value use std::sync::Arc; -use std::thread::Thread; +use std::thread; fn main() { let v = vec!(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); let arc_v = Arc::new(v); - Thread::spawn(move|| { + thread::spawn(move|| { assert_eq!((*arc_v)[3], 4); }); diff --git a/src/test/compile-fail/no-reuse-move-arc.rs b/src/test/compile-fail/no-reuse-move-arc.rs index 730ba9ab9ea71..1720b40c83bbd 100644 --- a/src/test/compile-fail/no-reuse-move-arc.rs +++ b/src/test/compile-fail/no-reuse-move-arc.rs @@ -9,13 +9,13 @@ // except according to those terms. use std::sync::Arc; -use std::thread::Thread; +use std::thread; fn main() { let v = vec!(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); let arc_v = Arc::new(v); - Thread::spawn(move|| { + thread::spawn(move|| { assert_eq!((*arc_v)[3], 4); }); diff --git a/src/test/compile-fail/no-send-res-ports.rs b/src/test/compile-fail/no-send-res-ports.rs index ae2847aab0963..5ebc386109a8b 100644 --- a/src/test/compile-fail/no-send-res-ports.rs +++ b/src/test/compile-fail/no-send-res-ports.rs @@ -10,7 +10,7 @@ #![feature(unsafe_destructor)] -use std::thread::Thread; +use std::thread; use std::rc::Rc; #[derive(Debug)] @@ -35,7 +35,7 @@ fn main() { let x = foo(Port(Rc::new(()))); - Thread::spawn(move|| { + thread::spawn(move|| { //~^ ERROR `core::marker::Send` is not implemented let y = x; println!("{:?}", y); diff --git a/src/test/run-fail/panic-task-name-none.rs b/src/test/run-fail/panic-task-name-none.rs index 816ee84a8410a..40a881852f5fc 100644 --- a/src/test/run-fail/panic-task-name-none.rs +++ b/src/test/run-fail/panic-task-name-none.rs @@ -10,10 +10,10 @@ // error-pattern:thread '' panicked at 'test' -use std::thread::Thread; +use std::thread; fn main() { - let r: Result = Thread::scoped(move|| { + let r: Result = thread::spawn(move|| { panic!("test"); 1 }).join(); diff --git a/src/test/run-fail/rt-set-exit-status-panic2.rs b/src/test/run-fail/rt-set-exit-status-panic2.rs index 446ef6f97e297..775d38c8b3044 100644 --- a/src/test/run-fail/rt-set-exit-status-panic2.rs +++ b/src/test/run-fail/rt-set-exit-status-panic2.rs @@ -12,7 +12,7 @@ #[macro_use] extern crate log; use std::os; -use std::thread::Thread; +use std::thread; struct r { x:int, @@ -35,7 +35,7 @@ fn r(x:int) -> r { fn main() { error!("whatever"); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let _i = r(5); }); panic!(); diff --git a/src/test/run-fail/task-spawn-barefn.rs b/src/test/run-fail/task-spawn-barefn.rs index d58148810da1f..406f7dbcb67fe 100644 --- a/src/test/run-fail/task-spawn-barefn.rs +++ b/src/test/run-fail/task-spawn-barefn.rs @@ -10,12 +10,12 @@ // error-pattern:Ensure that the child task runs by panicking -use std::thread::Thread; +use std::thread; fn main() { // the purpose of this test is to make sure that task::spawn() // works when provided with a bare function: - let r = Thread::scoped(startfn).join(); + let r = thread::spawn(startfn).join(); if r.is_err() { panic!() } diff --git a/src/test/run-pass/unique-send-2.rs b/src/test/run-pass/unique-send-2.rs index f0b634c0d44a7..08ffe40369626 100644 --- a/src/test/run-pass/unique-send-2.rs +++ b/src/test/run-pass/unique-send-2.rs @@ -12,7 +12,7 @@ #![feature(box_syntax)] use std::sync::mpsc::{channel, Sender}; -use std::thread::Thread; +use std::thread; fn child(tx: &Sender>, i: uint) { tx.send(box i).unwrap(); @@ -25,7 +25,7 @@ pub fn main() { let _t = (0u..n).map(|i| { expected += i; let tx = tx.clone(); - Thread::scoped(move|| { + thread::spawn(move|| { child(&tx, i) }) }).collect::>(); diff --git a/src/test/run-pass/unit-like-struct-drop-run.rs b/src/test/run-pass/unit-like-struct-drop-run.rs index 0acf736e2ab5c..ac46187f03a71 100644 --- a/src/test/run-pass/unit-like-struct-drop-run.rs +++ b/src/test/run-pass/unit-like-struct-drop-run.rs @@ -11,7 +11,7 @@ // Make sure the destructor is run for unit-like structs. use std::boxed::BoxAny; -use std::thread::Thread; +use std::thread; struct Foo; @@ -22,7 +22,7 @@ impl Drop for Foo { } pub fn main() { - let x = Thread::scoped(move|| { + let x = thread::spawn(move|| { let _b = Foo; }).join(); diff --git a/src/test/run-pass/unwind-resource.rs b/src/test/run-pass/unwind-resource.rs index 159bac101830a..52c09aadfbd7b 100644 --- a/src/test/run-pass/unwind-resource.rs +++ b/src/test/run-pass/unwind-resource.rs @@ -9,7 +9,7 @@ // except according to those terms. use std::sync::mpsc::{channel, Sender}; -use std::thread::Thread; +use std::thread; struct complainer { tx: Sender, @@ -37,7 +37,7 @@ fn f(tx: Sender) { pub fn main() { let (tx, rx) = channel(); - let _t = Thread::scoped(move|| f(tx.clone())); + let _t = thread::spawn(move|| f(tx.clone())); println!("hiiiiiiiii"); assert!(rx.recv().unwrap()); } diff --git a/src/test/run-pass/unwind-unique.rs b/src/test/run-pass/unwind-unique.rs index ea52802d24578..d38b6e79eba66 100644 --- a/src/test/run-pass/unwind-unique.rs +++ b/src/test/run-pass/unwind-unique.rs @@ -11,7 +11,7 @@ #![allow(unknown_features)] #![feature(box_syntax)] -use std::thread::Thread; +use std::thread; fn f() { let _a = box 0; @@ -19,5 +19,5 @@ fn f() { } pub fn main() { - let _t = Thread::scoped(f); + let _t = thread::spawn(f); } diff --git a/src/test/run-pass/vector-sort-panic-safe.rs b/src/test/run-pass/vector-sort-panic-safe.rs index d13369b1f5258..da9cf35813b5b 100644 --- a/src/test/run-pass/vector-sort-panic-safe.rs +++ b/src/test/run-pass/vector-sort-panic-safe.rs @@ -10,7 +10,7 @@ use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering}; use std::rand::{thread_rng, Rng, Rand}; -use std::thread::Thread; +use std::thread; const REPEATS: usize = 5; const MAX_LEN: usize = 32; @@ -79,7 +79,7 @@ pub fn main() { let v = main.clone(); - let _ = Thread::scoped(move|| { + let _ = thread::spawn(move|| { let mut v = v; let mut panic_countdown = panic_countdown; v.sort_by(|a, b| { diff --git a/src/test/run-pass/weak-lang-item.rs b/src/test/run-pass/weak-lang-item.rs index b1c65d322ab20..741e8be02f72c 100644 --- a/src/test/run-pass/weak-lang-item.rs +++ b/src/test/run-pass/weak-lang-item.rs @@ -12,10 +12,10 @@ extern crate "weak-lang-items" as other; -use std::thread::Thread; +use std::thread; fn main() { - let _ = Thread::scoped(move|| { + let _ = thread::spawn(move|| { other::foo() }); } diff --git a/src/test/run-pass/yield.rs b/src/test/run-pass/yield.rs index 9ad6dd9d2b142..45a747509589d 100644 --- a/src/test/run-pass/yield.rs +++ b/src/test/run-pass/yield.rs @@ -8,18 +8,18 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::thread::Thread; +use std::thread; pub fn main() { - let mut result = Thread::scoped(child); + let mut result = thread::spawn(child); println!("1"); - Thread::yield_now(); + thread::yield_now(); println!("2"); - Thread::yield_now(); + thread::yield_now(); println!("3"); result.join(); } fn child() { - println!("4"); Thread::yield_now(); println!("5"); Thread::yield_now(); println!("6"); + println!("4"); thread::yield_now(); println!("5"); thread::yield_now(); println!("6"); } diff --git a/src/test/run-pass/yield1.rs b/src/test/run-pass/yield1.rs index 3d3a36021da15..69d8431082c2f 100644 --- a/src/test/run-pass/yield1.rs +++ b/src/test/run-pass/yield1.rs @@ -8,12 +8,12 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::thread::Thread; +use std::thread; pub fn main() { - let mut result = Thread::scoped(child); + let mut result = thread::spawn(child); println!("1"); - Thread::yield_now(); + thread::yield_now(); result.join(); } diff --git a/src/test/run-pass/yield2.rs b/src/test/run-pass/yield2.rs index 66ad7de0296b1..56dc02c6d2e67 100644 --- a/src/test/run-pass/yield2.rs +++ b/src/test/run-pass/yield2.rs @@ -8,9 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::thread::Thread; +use std::thread; pub fn main() { let mut i: int = 0; - while i < 100 { i = i + 1; println!("{}", i); Thread::yield_now(); } + while i < 100 { i = i + 1; println!("{}", i); thread::yield_now(); } }