about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorAaron Turon <aturon@mozilla.com>2015-01-05 21:59:45 -0800
committerAaron Turon <aturon@mozilla.com>2015-01-06 14:57:52 -0800
commitcaca9b2e7109a148d100a3c6851241d3815da3db (patch)
treeb49ae965c7392d0c527aba9c427d4e9e224f8750 /src/libstd
parentf67b81e8d4dc198ad10ad50a7624e43cc1e25802 (diff)
downloadrust-caca9b2e7109a148d100a3c6851241d3815da3db.tar.gz
rust-caca9b2e7109a148d100a3c6851241d3815da3db.zip
Fallout from stabilization
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/io/comm_adapters.rs6
-rw-r--r--src/libstd/io/mod.rs10
-rw-r--r--src/libstd/io/net/pipe.rs12
-rw-r--r--src/libstd/io/net/tcp.rs26
-rw-r--r--src/libstd/io/process.rs2
-rw-r--r--src/libstd/io/timer.rs6
-rw-r--r--src/libstd/macros.rs4
-rw-r--r--src/libstd/path/posix.rs6
-rw-r--r--src/libstd/path/windows.rs6
-rw-r--r--src/libstd/rand/os.rs2
-rw-r--r--src/libstd/sync/barrier.rs4
-rw-r--r--src/libstd/sync/condvar.rs4
-rw-r--r--src/libstd/sync/future.rs2
-rw-r--r--src/libstd/sync/mpsc/mod.rs68
-rw-r--r--src/libstd/sync/mpsc/mpsc_queue.rs2
-rw-r--r--src/libstd/sync/mutex.rs12
-rw-r--r--src/libstd/sync/once.rs2
-rw-r--r--src/libstd/sync/rwlock.rs16
-rw-r--r--src/libstd/sync/semaphore.rs2
-rw-r--r--src/libstd/sync/task_pool.rs2
-rw-r--r--src/libstd/sys/common/helper_thread.rs2
-rw-r--r--src/libstd/thread.rs41
-rw-r--r--src/libstd/thread_local/mod.rs8
23 files changed, 123 insertions, 122 deletions
diff --git a/src/libstd/io/comm_adapters.rs b/src/libstd/io/comm_adapters.rs
index f47f6237b72..9ccede09cfc 100644
--- a/src/libstd/io/comm_adapters.rs
+++ b/src/libstd/io/comm_adapters.rs
@@ -172,7 +172,7 @@ mod test {
           tx.send(vec![3u8, 4u8]).unwrap();
           tx.send(vec![5u8, 6u8]).unwrap();
           tx.send(vec![7u8, 8u8]).unwrap();
-        }).detach();
+        });
 
         let mut reader = ChanReader::new(rx);
         let mut buf = [0u8; 3];
@@ -215,7 +215,7 @@ mod test {
           tx.send(b"rld\nhow ".to_vec()).unwrap();
           tx.send(b"are you?".to_vec()).unwrap();
           tx.send(b"".to_vec()).unwrap();
-        }).detach();
+        });
 
         let mut reader = ChanReader::new(rx);
 
@@ -234,7 +234,7 @@ mod test {
         writer.write_be_u32(42).unwrap();
 
         let wanted = vec![0u8, 0u8, 0u8, 42u8];
-        let got = match Thread::spawn(move|| { rx.recv().unwrap() }).join() {
+        let got = match Thread::scoped(move|| { rx.recv().unwrap() }).join() {
             Ok(got) => got,
             Err(_) => panic!(),
         };
diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs
index 5bef473db99..46c59ec49c1 100644
--- a/src/libstd/io/mod.rs
+++ b/src/libstd/io/mod.rs
@@ -120,10 +120,12 @@
 //!     for stream in acceptor.incoming() {
 //!         match stream {
 //!             Err(e) => { /* connection failed */ }
-//!             Ok(stream) => Thread::spawn(move|| {
-//!                 // connection succeeded
-//!                 handle_client(stream)
-//!             }).detach()
+//!             Ok(stream) => {
+//!                 Thread::spawn(move|| {
+//!                     // connection succeeded
+//!                     handle_client(stream)
+//!                 });
+//!             }
 //!         }
 //!     }
 //!
diff --git a/src/libstd/io/net/pipe.rs b/src/libstd/io/net/pipe.rs
index 738c70412f7..29295b5751c 100644
--- a/src/libstd/io/net/pipe.rs
+++ b/src/libstd/io/net/pipe.rs
@@ -608,7 +608,7 @@ mod tests {
             let mut a = a;
             let _s = a.accept().unwrap();
             let _ = rx.recv();
-        }).detach();
+        });
 
         let mut b = [0];
         let mut s = UnixStream::connect(&addr).unwrap();
@@ -645,7 +645,7 @@ mod tests {
             let mut a = a;
             let _s = a.accept().unwrap();
             let _ = rx.recv();
-        }).detach();
+        });
 
         let mut s = UnixStream::connect(&addr).unwrap();
         let s2 = s.clone();
@@ -672,7 +672,7 @@ mod tests {
             rx.recv().unwrap();
             assert!(s.write(&[0]).is_ok());
             let _ = rx.recv();
-        }).detach();
+        });
 
         let mut s = a.accept().unwrap();
         s.set_timeout(Some(20));
@@ -716,7 +716,7 @@ mod tests {
                 }
             }
             let _ = rx.recv();
-        }).detach();
+        });
 
         let mut s = a.accept().unwrap();
         s.set_read_timeout(Some(20));
@@ -739,7 +739,7 @@ mod tests {
             rx.recv().unwrap();
             assert!(s.write(&[0]).is_ok());
             let _ = rx.recv();
-        }).detach();
+        });
 
         let mut s = a.accept().unwrap();
         s.set_write_timeout(Some(20));
@@ -766,7 +766,7 @@ mod tests {
             rx.recv().unwrap();
             assert!(s.write(&[0]).is_ok());
             let _ = rx.recv();
-        }).detach();
+        });
 
         let mut s = a.accept().unwrap();
         let s2 = s.clone();
diff --git a/src/libstd/io/net/tcp.rs b/src/libstd/io/net/tcp.rs
index 3e59aaa05ef..b1762ff26fc 100644
--- a/src/libstd/io/net/tcp.rs
+++ b/src/libstd/io/net/tcp.rs
@@ -146,7 +146,7 @@ impl TcpStream {
     ///     timer::sleep(Duration::seconds(1));
     ///     let mut stream = stream2;
     ///     stream.close_read();
-    /// }).detach();
+    /// });
     ///
     /// // wait for some data, will get canceled after one second
     /// let mut buf = [0];
@@ -295,10 +295,12 @@ impl sys_common::AsInner<TcpStreamImp> for TcpStream {
 /// for stream in acceptor.incoming() {
 ///     match stream {
 ///         Err(e) => { /* connection failed */ }
-///         Ok(stream) => Thread::spawn(move|| {
-///             // connection succeeded
-///             handle_client(stream)
-///         }).detach()
+///         Ok(stream) => {
+///             Thread::spawn(move|| {
+///                 // connection succeeded
+///                 handle_client(stream)
+///             });
+///         }
 ///     }
 /// }
 ///
@@ -432,7 +434,7 @@ impl TcpAcceptor {
     ///             Err(e) => panic!("unexpected error: {}", e),
     ///         }
     ///     }
-    /// }).detach();
+    /// });
     ///
     /// # fn wait_for_sigint() {}
     /// // Now that our accept loop is running, wait for the program to be
@@ -1186,7 +1188,7 @@ mod test {
             let mut a = a;
             let _s = a.accept().unwrap();
             let _ = rx.recv().unwrap();
-        }).detach();
+        });
 
         let mut b = [0];
         let mut s = TcpStream::connect(addr).unwrap();
@@ -1223,7 +1225,7 @@ mod test {
             let mut a = a;
             let _s = a.accept().unwrap();
             let _ = rx.recv().unwrap();
-        }).detach();
+        });
 
         let mut s = TcpStream::connect(addr).unwrap();
         let s2 = s.clone();
@@ -1250,7 +1252,7 @@ mod test {
             rx.recv().unwrap();
             assert!(s.write(&[0]).is_ok());
             let _ = rx.recv();
-        }).detach();
+        });
 
         let mut s = a.accept().unwrap();
         s.set_timeout(Some(20));
@@ -1289,7 +1291,7 @@ mod test {
                 }
             }
             let _ = rx.recv();
-        }).detach();
+        });
 
         let mut s = a.accept().unwrap();
         s.set_read_timeout(Some(20));
@@ -1312,7 +1314,7 @@ mod test {
             rx.recv().unwrap();
             assert!(s.write(&[0]).is_ok());
             let _ = rx.recv();
-        }).detach();
+        });
 
         let mut s = a.accept().unwrap();
         s.set_write_timeout(Some(20));
@@ -1340,7 +1342,7 @@ mod test {
             rx.recv().unwrap();
             assert_eq!(s.write(&[0]), Ok(()));
             let _ = rx.recv();
-        }).detach();
+        });
 
         let mut s = a.accept().unwrap();
         let s2 = s.clone();
diff --git a/src/libstd/io/process.rs b/src/libstd/io/process.rs
index ea232ad0c3f..d7452180ffa 100644
--- a/src/libstd/io/process.rs
+++ b/src/libstd/io/process.rs
@@ -705,7 +705,7 @@ impl Process {
                     Thread::spawn(move |:| {
                         let mut stream = stream;
                         tx.send(stream.read_to_end()).unwrap();
-                    }).detach();
+                    });
                 }
                 None => tx.send(Ok(Vec::new())).unwrap()
             }
diff --git a/src/libstd/io/timer.rs b/src/libstd/io/timer.rs
index e073f76af82..8a0445be471 100644
--- a/src/libstd/io/timer.rs
+++ b/src/libstd/io/timer.rs
@@ -358,7 +358,7 @@ mod test {
 
         Thread::spawn(move|| {
             let _ = timer_rx.recv();
-        }).detach();
+        });
 
         // when we drop the TimerWatcher we're going to destroy the channel,
         // which must wake up the task on the other end
@@ -372,7 +372,7 @@ mod test {
 
         Thread::spawn(move|| {
             let _ = timer_rx.recv();
-        }).detach();
+        });
 
         timer.oneshot(Duration::milliseconds(1));
     }
@@ -385,7 +385,7 @@ mod test {
 
         Thread::spawn(move|| {
             let _ = timer_rx.recv();
-        }).detach();
+        });
 
         timer.sleep(Duration::milliseconds(1));
     }
diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs
index d96441e09a8..092430bf082 100644
--- a/src/libstd/macros.rs
+++ b/src/libstd/macros.rs
@@ -303,8 +303,8 @@ macro_rules! try {
 /// # fn long_running_task() {}
 /// # fn calculate_the_answer() -> int { 42i }
 ///
-/// Thread::spawn(move|| { long_running_task(); tx1.send(()) }).detach();
-/// Thread::spawn(move|| { tx2.send(calculate_the_answer()) }).detach();
+/// 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/path/posix.rs b/src/libstd/path/posix.rs
index d9981ace030..ece9a343841 100644
--- a/src/libstd/path/posix.rs
+++ b/src/libstd/path/posix.rs
@@ -502,17 +502,17 @@ mod tests {
     #[test]
     fn test_null_byte() {
         use thread::Thread;
-        let result = Thread::spawn(move|| {
+        let result = Thread::scoped(move|| {
             Path::new(b"foo/bar\0")
         }).join();
         assert!(result.is_err());
 
-        let result = Thread::spawn(move|| {
+        let result = Thread::scoped(move|| {
             Path::new("test").set_filename(b"f\0o")
         }).join();
         assert!(result.is_err());
 
-        let result = Thread::spawn(move|| {
+        let result = Thread::scoped(move|| {
             Path::new("test").push(b"f\0o");
         }).join();
         assert!(result.is_err());
diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs
index 4b5d793355b..db3224e66e4 100644
--- a/src/libstd/path/windows.rs
+++ b/src/libstd/path/windows.rs
@@ -1287,17 +1287,17 @@ mod tests {
     #[test]
     fn test_null_byte() {
         use thread::Thread;
-        let result = Thread::spawn(move|| {
+        let result = Thread::scoped(move|| {
             Path::new(b"foo/bar\0")
         }).join();
         assert!(result.is_err());
 
-        let result = Thread::spawn(move|| {
+        let result = Thread::scoped(move|| {
             Path::new("test").set_filename(b"f\0o")
         }).join();
         assert!(result.is_err());
 
-        let result = Thread::spawn(move || {
+        let result = Thread::scoped(move || {
             Path::new("test").push(b"f\0o");
         }).join();
         assert!(result.is_err());
diff --git a/src/libstd/rand/os.rs b/src/libstd/rand/os.rs
index a79a6e35ebc..d9c019e3ace 100644
--- a/src/libstd/rand/os.rs
+++ b/src/libstd/rand/os.rs
@@ -397,7 +397,7 @@ mod test {
                     r.fill_bytes(&mut v);
                     Thread::yield_now();
                 }
-            }).detach();
+            });
         }
 
         // start all the tasks
diff --git a/src/libstd/sync/barrier.rs b/src/libstd/sync/barrier.rs
index bf5da3e7cba..70939879400 100644
--- a/src/libstd/sync/barrier.rs
+++ b/src/libstd/sync/barrier.rs
@@ -26,7 +26,7 @@ use sync::{Mutex, Condvar};
 ///         println!("before wait");
 ///         c.wait();
 ///         println!("after wait");
-///     }).detach();
+///     });
 /// }
 /// ```
 #[stable]
@@ -126,7 +126,7 @@ mod tests {
             let tx = tx.clone();
             Thread::spawn(move|| {
                 tx.send(c.wait().is_leader()).unwrap();
-            }).detach();
+            });
         }
 
         // At this point, all spawned tasks should be blocked,
diff --git a/src/libstd/sync/condvar.rs b/src/libstd/sync/condvar.rs
index e97be51fdbc..3c0ae71255d 100644
--- a/src/libstd/sync/condvar.rs
+++ b/src/libstd/sync/condvar.rs
@@ -48,7 +48,7 @@ use sync::{mutex, MutexGuard};
 ///     let mut started = lock.lock().unwrap();
 ///     *started = true;
 ///     cvar.notify_one();
-/// }).detach();
+/// });
 ///
 /// // wait for the thread to start up
 /// let &(ref lock, ref cvar) = &*pair;
@@ -338,7 +338,7 @@ mod tests {
                     cnt = cond.wait(cnt).unwrap();
                 }
                 tx.send(()).unwrap();
-            }).detach();
+            });
         }
         drop(tx);
 
diff --git a/src/libstd/sync/future.rs b/src/libstd/sync/future.rs
index 4c6adcc04f6..568c24446e7 100644
--- a/src/libstd/sync/future.rs
+++ b/src/libstd/sync/future.rs
@@ -141,7 +141,7 @@ impl<A:Send> Future<A> {
         Thread::spawn(move |:| {
             // Don't panic if the other end has hung up
             let _ = tx.send(blk());
-        }).detach();
+        });
 
         Future::from_receiver(rx)
     }
diff --git a/src/libstd/sync/mpsc/mod.rs b/src/libstd/sync/mpsc/mod.rs
index 7c18b8a43fa..72c453f7f71 100644
--- a/src/libstd/sync/mpsc/mod.rs
+++ b/src/libstd/sync/mpsc/mod.rs
@@ -60,7 +60,7 @@
 //! let (tx, rx) = channel();
 //! Thread::spawn(move|| {
 //!     tx.send(10i).unwrap();
-//! }).detach();
+//! });
 //! assert_eq!(rx.recv().unwrap(), 10i);
 //! ```
 //!
@@ -78,7 +78,7 @@
 //!     let tx = tx.clone();
 //!     Thread::spawn(move|| {
 //!         tx.send(i).unwrap();
-//!     }).detach()
+//!     });
 //! }
 //!
 //! for _ in range(0i, 10i) {
@@ -109,7 +109,7 @@
 //! Thread::spawn(move|| {
 //!     // This will wait for the parent task to start receiving
 //!     tx.send(53).unwrap();
-//! }).detach();
+//! });
 //! rx.recv().unwrap();
 //! ```
 //!
@@ -476,7 +476,7 @@ impl<T> UnsafeFlavor<T> for Receiver<T> {
 /// Thread::spawn(move|| {
 /// #   fn expensive_computation() {}
 ///     tx.send(expensive_computation()).unwrap();
-/// }).detach();
+/// });
 ///
 /// // Do some useful work for awhile
 ///
@@ -518,7 +518,7 @@ pub fn channel<T: Send>() -> (Sender<T>, Receiver<T>) {
 /// Thread::spawn(move|| {
 ///     // this will block until the previous message has been received
 ///     tx.send(2i).unwrap();
-/// }).detach();
+/// });
 ///
 /// assert_eq!(rx.recv().unwrap(), 1i);
 /// assert_eq!(rx.recv().unwrap(), 2i);
@@ -1144,7 +1144,7 @@ mod test {
     #[test]
     fn stress() {
         let (tx, rx) = channel::<int>();
-        let t = Thread::spawn(move|| {
+        let t = Thread::scoped(move|| {
             for _ in range(0u, 10000) { tx.send(1i).unwrap(); }
         });
         for _ in range(0u, 10000) {
@@ -1159,7 +1159,7 @@ mod test {
         static NTHREADS: uint = 8;
         let (tx, rx) = channel::<int>();
 
-        let t = Thread::spawn(move|| {
+        let t = Thread::scoped(move|| {
             for _ in range(0, AMT * NTHREADS) {
                 assert_eq!(rx.recv().unwrap(), 1);
             }
@@ -1173,7 +1173,7 @@ mod test {
             let tx = tx.clone();
             Thread::spawn(move|| {
                 for _ in range(0, AMT) { tx.send(1).unwrap(); }
-            }).detach();
+            });
         }
         drop(tx);
         t.join().ok().unwrap();
@@ -1183,14 +1183,14 @@ mod test {
     fn send_from_outside_runtime() {
         let (tx1, rx1) = channel::<()>();
         let (tx2, rx2) = channel::<int>();
-        let t1 = Thread::spawn(move|| {
+        let t1 = Thread::scoped(move|| {
             tx1.send(()).unwrap();
             for _ in range(0i, 40) {
                 assert_eq!(rx2.recv().unwrap(), 1);
             }
         });
         rx1.recv().unwrap();
-        let t2 = Thread::spawn(move|| {
+        let t2 = Thread::scoped(move|| {
             for _ in range(0i, 40) {
                 tx2.send(1).unwrap();
             }
@@ -1202,7 +1202,7 @@ mod test {
     #[test]
     fn recv_from_outside_runtime() {
         let (tx, rx) = channel::<int>();
-        let t = Thread::spawn(move|| {
+        let t = Thread::scoped(move|| {
             for _ in range(0i, 40) {
                 assert_eq!(rx.recv().unwrap(), 1);
             }
@@ -1217,11 +1217,11 @@ mod test {
     fn no_runtime() {
         let (tx1, rx1) = channel::<int>();
         let (tx2, rx2) = channel::<int>();
-        let t1 = Thread::spawn(move|| {
+        let t1 = Thread::scoped(move|| {
             assert_eq!(rx1.recv().unwrap(), 1);
             tx2.send(2).unwrap();
         });
-        let t2 = Thread::spawn(move|| {
+        let t2 = Thread::scoped(move|| {
             tx1.send(1).unwrap();
             assert_eq!(rx2.recv().unwrap(), 2);
         });
@@ -1254,7 +1254,7 @@ mod test {
     #[test]
     fn oneshot_single_thread_recv_chan_close() {
         // Receiving on a closed chan will panic
-        let res = Thread::spawn(move|| {
+        let res = Thread::scoped(move|| {
             let (tx, rx) = channel::<int>();
             drop(tx);
             rx.recv().unwrap();
@@ -1336,7 +1336,7 @@ mod test {
         let _t = Thread::spawn(move|| {
             drop(tx);
         });
-        let res = Thread::spawn(move|| {
+        let res = Thread::scoped(move|| {
             assert!(rx.recv().unwrap() == box 10);
         }).join();
         assert!(res.is_err());
@@ -1360,7 +1360,7 @@ mod test {
             let _t = Thread::spawn(move|| {
                 drop(rx);
             });
-            let _ = Thread::spawn(move|| {
+            let _ = Thread::scoped(move|| {
                 tx.send(1).unwrap();
             }).join();
         }
@@ -1371,15 +1371,15 @@ mod test {
         for _ in range(0, stress_factor()) {
             let (tx, rx) = channel::<int>();
             Thread::spawn(move|| {
-                let res = Thread::spawn(move|| {
+                let res = Thread::scoped(move|| {
                     rx.recv().unwrap();
                 }).join();
                 assert!(res.is_err());
-            }).detach();
+            });
             let _t = Thread::spawn(move|| {
                 Thread::spawn(move|| {
                     drop(tx);
-                }).detach();
+                });
             });
         }
     }
@@ -1409,7 +1409,7 @@ mod test {
                 Thread::spawn(move|| {
                     tx.send(box i).unwrap();
                     send(tx, i + 1);
-                }).detach();
+                });
             }
 
             fn recv(rx: Receiver<Box<int>>, i: int) {
@@ -1418,7 +1418,7 @@ mod test {
                 Thread::spawn(move|| {
                     assert!(rx.recv().unwrap() == box i);
                     recv(rx, i + 1);
-                }).detach();
+                });
             }
         }
     }
@@ -1439,7 +1439,7 @@ mod test {
             let tx = tx.clone();
             Thread::spawn(move|| {
                 tx.send(()).unwrap();
-            }).detach();
+            });
         }
 
         for _ in range(0, total) {
@@ -1644,7 +1644,7 @@ mod sync_tests {
         Thread::spawn(move|| {
             tx.send(1).unwrap();
             tx.send(1).unwrap();
-        }).detach();
+        });
         while rx.recv().is_ok() {}
     }
 
@@ -1653,7 +1653,7 @@ mod sync_tests {
         let (tx, rx) = sync_channel::<int>(0);
         Thread::spawn(move|| {
             for _ in range(0u, 10000) { tx.send(1).unwrap(); }
-        }).detach();
+        });
         for _ in range(0u, 10000) {
             assert_eq!(rx.recv().unwrap(), 1);
         }
@@ -1675,13 +1675,13 @@ mod sync_tests {
                 _ => {}
             }
             dtx.send(()).unwrap();
-        }).detach();
+        });
 
         for _ in range(0, NTHREADS) {
             let tx = tx.clone();
             Thread::spawn(move|| {
                 for _ in range(0, AMT) { tx.send(1).unwrap(); }
-            }).detach();
+            });
         }
         drop(tx);
         drx.recv().unwrap();
@@ -1712,7 +1712,7 @@ mod sync_tests {
     #[test]
     fn oneshot_single_thread_recv_chan_close() {
         // Receiving on a closed chan will panic
-        let res = Thread::spawn(move|| {
+        let res = Thread::scoped(move|| {
             let (tx, rx) = sync_channel::<int>(0);
             drop(tx);
             rx.recv().unwrap();
@@ -1800,7 +1800,7 @@ mod sync_tests {
         let _t = Thread::spawn(move|| {
             drop(tx);
         });
-        let res = Thread::spawn(move|| {
+        let res = Thread::scoped(move|| {
             assert!(rx.recv().unwrap() == box 10);
         }).join();
         assert!(res.is_err());
@@ -1824,7 +1824,7 @@ mod sync_tests {
             let _t = Thread::spawn(move|| {
                 drop(rx);
             });
-            let _ = Thread::spawn(move || {
+            let _ = Thread::scoped(move || {
                 tx.send(1).unwrap();
             }).join();
         }
@@ -1835,7 +1835,7 @@ mod sync_tests {
         for _ in range(0, stress_factor()) {
             let (tx, rx) = sync_channel::<int>(0);
             let _t = Thread::spawn(move|| {
-                let res = Thread::spawn(move|| {
+                let res = Thread::scoped(move|| {
                     rx.recv().unwrap();
                 }).join();
                 assert!(res.is_err());
@@ -1843,7 +1843,7 @@ mod sync_tests {
             let _t = Thread::spawn(move|| {
                 Thread::spawn(move|| {
                     drop(tx);
-                }).detach();
+                });
             });
         }
     }
@@ -1873,7 +1873,7 @@ mod sync_tests {
                 Thread::spawn(move|| {
                     tx.send(box i).unwrap();
                     send(tx, i + 1);
-                }).detach();
+                });
             }
 
             fn recv(rx: Receiver<Box<int>>, i: int) {
@@ -1882,7 +1882,7 @@ mod sync_tests {
                 Thread::spawn(move|| {
                     assert!(rx.recv().unwrap() == box i);
                     recv(rx, i + 1);
-                }).detach();
+                });
             }
         }
     }
@@ -1903,7 +1903,7 @@ mod sync_tests {
             let tx = tx.clone();
             Thread::spawn(move|| {
                 tx.send(()).unwrap();
-            }).detach();
+            });
         }
 
         for _ in range(0, total) {
diff --git a/src/libstd/sync/mpsc/mpsc_queue.rs b/src/libstd/sync/mpsc/mpsc_queue.rs
index 9ad24a5a11e..f8eae1322bf 100644
--- a/src/libstd/sync/mpsc/mpsc_queue.rs
+++ b/src/libstd/sync/mpsc/mpsc_queue.rs
@@ -188,7 +188,7 @@ mod tests {
                     q.push(i);
                 }
                 tx.send(()).unwrap();
-            }).detach();
+            });
         }
 
         let mut i = 0u;
diff --git a/src/libstd/sync/mutex.rs b/src/libstd/sync/mutex.rs
index 6b3dd89f33b..6eef428f558 100644
--- a/src/libstd/sync/mutex.rs
+++ b/src/libstd/sync/mutex.rs
@@ -75,7 +75,7 @@ use sys_common::mutex as sys;
 ///             tx.send(()).unwrap();
 ///         }
 ///         // the lock is unlocked here when `data` goes out of scope.
-///     }).detach();
+///     });
 /// }
 ///
 /// rx.recv().unwrap();
@@ -90,7 +90,7 @@ use sys_common::mutex as sys;
 /// let lock = Arc::new(Mutex::new(0u));
 /// let lock2 = lock.clone();
 ///
-/// let _ = Thread::spawn(move || -> () {
+/// let _ = Thread::scoped(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();
@@ -376,9 +376,9 @@ mod test {
         let (tx, rx) = channel();
         for _ in range(0, K) {
             let tx2 = tx.clone();
-            Thread::spawn(move|| { inc(); tx2.send(()).unwrap(); }).detach();
+            Thread::spawn(move|| { inc(); tx2.send(()).unwrap(); });
             let tx2 = tx.clone();
-            Thread::spawn(move|| { inc(); tx2.send(()).unwrap(); }).detach();
+            Thread::spawn(move|| { inc(); tx2.send(()).unwrap(); });
         }
 
         drop(tx);
@@ -453,7 +453,7 @@ mod test {
     fn test_mutex_arc_poison() {
         let arc = Arc::new(Mutex::new(1i));
         let arc2 = arc.clone();
-        let _ = Thread::spawn(move|| {
+        let _ = Thread::scoped(move|| {
             let lock = arc2.lock().unwrap();
             assert_eq!(*lock, 2);
         }).join();
@@ -480,7 +480,7 @@ mod test {
     fn test_mutex_arc_access_in_unwind() {
         let arc = Arc::new(Mutex::new(1i));
         let arc2 = arc.clone();
-        let _ = Thread::spawn(move|| -> () {
+        let _ = Thread::scoped(move|| -> () {
             struct Unwinder {
                 i: Arc<Mutex<int>>,
             }
diff --git a/src/libstd/sync/once.rs b/src/libstd/sync/once.rs
index aa2d957a3eb..b32faf2d03f 100644
--- a/src/libstd/sync/once.rs
+++ b/src/libstd/sync/once.rs
@@ -159,7 +159,7 @@ mod test {
                     assert!(run);
                 }
                 tx.send(()).unwrap();
-            }).detach();
+            });
         }
 
         unsafe {
diff --git a/src/libstd/sync/rwlock.rs b/src/libstd/sync/rwlock.rs
index 4afd5bb63f4..00b783d9661 100644
--- a/src/libstd/sync/rwlock.rs
+++ b/src/libstd/sync/rwlock.rs
@@ -411,7 +411,7 @@ mod tests {
                     }
                 }
                 drop(tx);
-            }).detach();
+            });
         }
         drop(tx);
         let _ = rx.recv();
@@ -422,7 +422,7 @@ mod tests {
     fn test_rw_arc_poison_wr() {
         let arc = Arc::new(RwLock::new(1i));
         let arc2 = arc.clone();
-        let _: Result<uint, _> = Thread::spawn(move|| {
+        let _: Result<uint, _> = Thread::scoped(move|| {
             let _lock = arc2.write().unwrap();
             panic!();
         }).join();
@@ -433,7 +433,7 @@ mod tests {
     fn test_rw_arc_poison_ww() {
         let arc = Arc::new(RwLock::new(1i));
         let arc2 = arc.clone();
-        let _: Result<uint, _> = Thread::spawn(move|| {
+        let _: Result<uint, _> = Thread::scoped(move|| {
             let _lock = arc2.write().unwrap();
             panic!();
         }).join();
@@ -444,7 +444,7 @@ mod tests {
     fn test_rw_arc_no_poison_rr() {
         let arc = Arc::new(RwLock::new(1i));
         let arc2 = arc.clone();
-        let _: Result<uint, _> = Thread::spawn(move|| {
+        let _: Result<uint, _> = Thread::scoped(move|| {
             let _lock = arc2.read().unwrap();
             panic!();
         }).join();
@@ -455,7 +455,7 @@ mod tests {
     fn test_rw_arc_no_poison_rw() {
         let arc = Arc::new(RwLock::new(1i));
         let arc2 = arc.clone();
-        let _: Result<uint, _> = Thread::spawn(move|| {
+        let _: Result<uint, _> = Thread::scoped(move|| {
             let _lock = arc2.read().unwrap();
             panic!()
         }).join();
@@ -478,13 +478,13 @@ mod tests {
                 *lock = tmp + 1;
             }
             tx.send(()).unwrap();
-        }).detach();
+        });
 
         // Readers try to catch the writer in the act
         let mut children = Vec::new();
         for _ in range(0u, 5) {
             let arc3 = arc.clone();
-            children.push(Thread::spawn(move|| {
+            children.push(Thread::scoped(move|| {
                 let lock = arc3.read().unwrap();
                 assert!(*lock >= 0);
             }));
@@ -505,7 +505,7 @@ mod tests {
     fn test_rw_arc_access_in_unwind() {
         let arc = Arc::new(RwLock::new(1i));
         let arc2 = arc.clone();
-        let _ = Thread::spawn(move|| -> () {
+        let _ = Thread::scoped(move|| -> () {
             struct Unwinder {
                 i: Arc<RwLock<int>>,
             }
diff --git a/src/libstd/sync/semaphore.rs b/src/libstd/sync/semaphore.rs
index 505819fbf8a..8d44084671a 100644
--- a/src/libstd/sync/semaphore.rs
+++ b/src/libstd/sync/semaphore.rs
@@ -193,7 +193,7 @@ mod tests {
                 tx.send(()).unwrap();
                 drop(s2.access());
                 tx.send(()).unwrap();
-            }).detach();
+            });
             rx.recv().unwrap(); // wait for child to come alive
         }
         rx.recv().unwrap(); // wait for child to be done
diff --git a/src/libstd/sync/task_pool.rs b/src/libstd/sync/task_pool.rs
index 088827dc084..278528bdb38 100644
--- a/src/libstd/sync/task_pool.rs
+++ b/src/libstd/sync/task_pool.rs
@@ -132,7 +132,7 @@ fn spawn_in_pool(jobs: Arc<Mutex<Receiver<Thunk>>>) {
         }
 
         sentinel.cancel();
-    }).detach();
+    });
 }
 
 #[cfg(test)]
diff --git a/src/libstd/sys/common/helper_thread.rs b/src/libstd/sys/common/helper_thread.rs
index bdf1bf3dfd0..f940b6ed368 100644
--- a/src/libstd/sys/common/helper_thread.rs
+++ b/src/libstd/sys/common/helper_thread.rs
@@ -99,7 +99,7 @@ impl<M: Send> Helper<M> {
                     let _g = self.lock.lock().unwrap();
                     *self.shutdown.get() = true;
                     self.cond.notify_one()
-                }).detach();
+                });
 
                 rt::at_exit(move|:| { self.shutdown() });
                 *self.initialized.get() = true;
diff --git a/src/libstd/thread.rs b/src/libstd/thread.rs
index 9e12a7b592a..5153b6b90a7 100644
--- a/src/libstd/thread.rs
+++ b/src/libstd/thread.rs
@@ -332,9 +332,6 @@ pub struct Thread {
     inner: Arc<Inner>,
 }
 
-#[stable]
-unsafe impl Sync for Thread {}
-
 impl Thread {
     // Used only internally to construct a thread object without spawning
     fn new(name: Option<String>) -> Thread {
@@ -520,14 +517,14 @@ mod test {
 
     #[test]
     fn test_unnamed_thread() {
-        Thread::spawn(move|| {
+        Thread::scoped(move|| {
             assert!(Thread::current().name().is_none());
         }).join().map_err(|_| ()).unwrap();
     }
 
     #[test]
     fn test_named_thread() {
-        Builder::new().name("ada lovelace".to_string()).spawn(move|| {
+        Builder::new().name("ada lovelace".to_string()).scoped(move|| {
             assert!(Thread::current().name().unwrap() == "ada lovelace".to_string());
         }).join().map_err(|_| ()).unwrap();
     }
@@ -537,13 +534,13 @@ mod test {
         let (tx, rx) = channel();
         Thread::spawn(move|| {
             tx.send(()).unwrap();
-        }).detach();
+        });
         rx.recv().unwrap();
     }
 
     #[test]
     fn test_join_success() {
-        match Thread::spawn(move|| -> String {
+        match Thread::scoped(move|| -> String {
             "Success!".to_string()
         }).join().as_ref().map(|s| s.as_slice()) {
             result::Result::Ok("Success!") => (),
@@ -553,7 +550,7 @@ mod test {
 
     #[test]
     fn test_join_panic() {
-        match Thread::spawn(move|| {
+        match Thread::scoped(move|| {
             panic!()
         }).join() {
             result::Result::Err(_) => (),
@@ -575,7 +572,7 @@ mod test {
                 } else {
                     f(i - 1, tx);
                 }
-            }).detach();
+            });
 
         }
         f(10, tx);
@@ -589,8 +586,8 @@ mod test {
         Thread::spawn(move|| {
             Thread::spawn(move|| {
                 tx.send(()).unwrap();
-            }).detach();
-        }).detach();
+            });
+        });
 
         rx.recv().unwrap();
     }
@@ -613,7 +610,7 @@ mod test {
     #[test]
     fn test_avoid_copying_the_body_spawn() {
         avoid_copying_the_body(|v| {
-            Thread::spawn(move || v.invoke(())).detach();
+            Thread::spawn(move || v.invoke(()));
         });
     }
 
@@ -622,14 +619,14 @@ mod test {
         avoid_copying_the_body(|f| {
             Thread::spawn(move|| {
                 f.invoke(());
-            }).detach();
+            });
         })
     }
 
     #[test]
     fn test_avoid_copying_the_body_join() {
         avoid_copying_the_body(|f| {
-            let _ = Thread::spawn(move|| {
+            let _ = Thread::scoped(move|| {
                 f.invoke(())
             }).join();
         })
@@ -645,21 +642,21 @@ mod test {
         fn child_no(x: uint) -> Thunk {
             return Thunk::new(move|| {
                 if x < GENERATIONS {
-                    Thread::spawn(move|| child_no(x+1).invoke(())).detach();
+                    Thread::spawn(move|| child_no(x+1).invoke(()));
                 }
             });
         }
-        Thread::spawn(|| child_no(0).invoke(())).detach();
+        Thread::spawn(|| child_no(0).invoke(()));
     }
 
     #[test]
     fn test_simple_newsched_spawn() {
-        Thread::spawn(move || {}).detach();
+        Thread::spawn(move || {});
     }
 
     #[test]
     fn test_try_panic_message_static_str() {
-        match Thread::spawn(move|| {
+        match Thread::scoped(move|| {
             panic!("static string");
         }).join() {
             Err(e) => {
@@ -673,7 +670,7 @@ mod test {
 
     #[test]
     fn test_try_panic_message_owned_str() {
-        match Thread::spawn(move|| {
+        match Thread::scoped(move|| {
             panic!("owned string".to_string());
         }).join() {
             Err(e) => {
@@ -687,7 +684,7 @@ mod test {
 
     #[test]
     fn test_try_panic_message_any() {
-        match Thread::spawn(move|| {
+        match Thread::scoped(move|| {
             panic!(box 413u16 as Box<Any + Send>);
         }).join() {
             Err(e) => {
@@ -705,7 +702,7 @@ mod test {
     fn test_try_panic_message_unit_struct() {
         struct Juju;
 
-        match Thread::spawn(move|| {
+        match Thread::scoped(move|| {
             panic!(Juju)
         }).join() {
             Err(ref e) if e.is::<Juju>() => {}
@@ -719,7 +716,7 @@ mod test {
         let mut reader = ChanReader::new(rx);
         let stdout = ChanWriter::new(tx);
 
-        let r = Builder::new().stdout(box stdout as Box<Writer + Send>).spawn(move|| {
+        let r = Builder::new().stdout(box stdout as Box<Writer + Send>).scoped(move|| {
             print!("Hello, world!");
         }).join();
         assert!(r.is_ok());
diff --git a/src/libstd/thread_local/mod.rs b/src/libstd/thread_local/mod.rs
index e0cbaa8ca50..c8cad7765e6 100644
--- a/src/libstd/thread_local/mod.rs
+++ b/src/libstd/thread_local/mod.rs
@@ -87,7 +87,7 @@ pub mod __impl {
 ///         assert_eq!(*f.borrow(), 1);
 ///         *f.borrow_mut() = 3;
 ///     });
-/// }).detach();
+/// });
 ///
 /// // we retain our original value of 2 despite the child thread
 /// FOO.with(|f| {
@@ -581,7 +581,7 @@ mod tests {
         }
         thread_local!(static FOO: Foo = foo());
 
-        Thread::spawn(|| {
+        Thread::scoped(|| {
             assert!(FOO.state() == State::Uninitialized);
             FOO.with(|_| {
                 assert!(FOO.state() == State::Valid);
@@ -645,7 +645,7 @@ mod tests {
             }
         }
 
-        Thread::spawn(move|| {
+        Thread::scoped(move|| {
             drop(S1);
         }).join().ok().unwrap();
     }
@@ -663,7 +663,7 @@ mod tests {
             }
         }
 
-        Thread::spawn(move|| unsafe {
+        Thread::scoped(move|| unsafe {
             K1.with(|s| *s.get() = Some(S1));
         }).join().ok().unwrap();
     }