]> git.lizzy.rs Git - rust.git/blobdiff - src/libstd/sync/mpsc/mod.rs
Mention the queueueue-ness of mpsc.
[rust.git] / src / libstd / sync / mpsc / mod.rs
index 893f353b1a72e406d8ff90ac4fb61cebd34edadb..2e60d684d6823aeb82a8c4248ad9fe8053a809ea 100644 (file)
@@ -8,7 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-//! Multi-producer, single-consumer communication primitives threads
+//! Multi-producer, single-consumer FIFO queue communication primitives.
 //!
 //! This module provides message-based communication over channels, concretely
 //! defined among three types:
@@ -59,9 +59,9 @@
 //! // Create a simple streaming channel
 //! let (tx, rx) = channel();
 //! Thread::spawn(move|| {
-//!     tx.send(10i).unwrap();
+//!     tx.send(10).unwrap();
 //! });
-//! assert_eq!(rx.recv().unwrap(), 10i);
+//! assert_eq!(rx.recv().unwrap(), 10);
 //! ```
 //!
 //! Shared usage:
 //! // where tx is the sending half (tx for transmission), and rx is the receiving
 //! // half (rx for receiving).
 //! let (tx, rx) = channel();
-//! for i in range(0i, 10i) {
+//! for i in 0..10 {
 //!     let tx = tx.clone();
 //!     Thread::spawn(move|| {
 //!         tx.send(i).unwrap();
 //!     });
 //! }
 //!
-//! for _ in range(0i, 10i) {
+//! for _ in 0..10 {
 //!     let j = rx.recv().unwrap();
 //!     assert!(0 <= j && j < 10);
 //! }
 //!
 //! ```no_run
 //! use std::sync::mpsc::channel;
-//! use std::io::timer::Timer;
+//! use std::old_io::timer::Timer;
 //! use std::time::Duration;
 //!
 //! let (tx, rx) = channel::<int>();
 //!
 //! ```no_run
 //! use std::sync::mpsc::channel;
-//! use std::io::timer::Timer;
+//! use std::old_io::timer::Timer;
 //! use std::time::Duration;
 //!
 //! let (tx, rx) = channel::<int>();
 //! }
 //! ```
 
-#![stable]
+#![stable(feature = "rust1", since = "1.0.0")]
 
 // A description of how Rust's channel implementation works
 //
 
 /// The receiving-half of Rust's channel type. This half can only be owned by
 /// one task
-#[stable]
+#[stable(feature = "rust1", since = "1.0.0")]
 pub struct Receiver<T> {
     inner: UnsafeCell<Flavor<T>>,
 }
@@ -350,14 +350,14 @@ unsafe impl<T:Send> Send for Receiver<T> { }
 /// An iterator over messages on a receiver, this iterator will block
 /// whenever `next` is called, waiting for a new message, and `None` will be
 /// returned when the corresponding channel has hung up.
-#[stable]
+#[stable(feature = "rust1", since = "1.0.0")]
 pub struct Iter<'a, T:'a> {
     rx: &'a Receiver<T>
 }
 
 /// The sending-half of Rust's asynchronous channel type. This half can only be
 /// owned by one task, but it can be cloned to send to other tasks.
-#[stable]
+#[stable(feature = "rust1", since = "1.0.0")]
 pub struct Sender<T> {
     inner: UnsafeCell<Flavor<T>>,
 }
@@ -368,7 +368,7 @@ unsafe impl<T:Send> Send for Sender<T> { }
 
 /// The sending-half of Rust's synchronous channel type. This half can only be
 /// owned by one task, but it can be cloned to send to other tasks.
-#[stable]
+#[stable(feature = "rust1", since = "1.0.0")]
 pub struct SyncSender<T> {
     inner: Arc<UnsafeCell<sync::Packet<T>>>,
 }
@@ -382,38 +382,38 @@ impl<T> !Sync for SyncSender<T> {}
 /// A `send` operation can only fail if the receiving end of a channel is
 /// disconnected, implying that the data could never be received. The error
 /// contains the data being sent as a payload so it can be recovered.
-#[derive(PartialEq, Eq)]
-#[stable]
+#[stable(feature = "rust1", since = "1.0.0")]
+#[derive(PartialEq, Eq, Clone, Copy)]
 pub struct SendError<T>(pub T);
 
 /// An error returned from the `recv` function on a `Receiver`.
 ///
 /// The `recv` operation can only fail if the sending half of a channel is
 /// disconnected, implying that no further messages will ever be received.
-#[derive(PartialEq, Eq, Clone, Copy, Show)]
-#[stable]
+#[derive(PartialEq, Eq, Clone, Copy, Debug)]
+#[stable(feature = "rust1", since = "1.0.0")]
 pub struct RecvError;
 
 /// This enumeration is the list of the possible reasons that try_recv could not
 /// return data when called.
-#[derive(PartialEq, Clone, Copy, Show)]
-#[stable]
+#[derive(PartialEq, Eq, Clone, Copy, Debug)]
+#[stable(feature = "rust1", since = "1.0.0")]
 pub enum TryRecvError {
     /// This channel is currently empty, but the sender(s) have not yet
     /// disconnected, so data may yet become available.
-    #[stable]
+    #[stable(feature = "rust1", since = "1.0.0")]
     Empty,
 
     /// This channel's sending half has become disconnected, and there will
     /// never be any more data received on this channel
-    #[stable]
+    #[stable(feature = "rust1", since = "1.0.0")]
     Disconnected,
 }
 
 /// This enumeration is the list of the possible error outcomes for the
 /// `SyncSender::try_send` method.
-#[derive(PartialEq, Clone)]
-#[stable]
+#[stable(feature = "rust1", since = "1.0.0")]
+#[derive(PartialEq, Eq, Clone, Copy)]
 pub enum TrySendError<T> {
     /// The data could not be sent on the channel because it would require that
     /// the callee block to send the data.
@@ -421,12 +421,12 @@ pub enum TrySendError<T> {
     /// If this is a buffered channel, then the buffer is full at this time. If
     /// this is not a buffered channel, then there is no receiver available to
     /// acquire the data.
-    #[stable]
+    #[stable(feature = "rust1", since = "1.0.0")]
     Full(T),
 
     /// This channel's receiving half has disconnected, so the data could not be
     /// sent. The data is returned back to the callee in this case.
-    #[stable]
+    #[stable(feature = "rust1", since = "1.0.0")]
     Disconnected(T),
 }
 
@@ -484,7 +484,7 @@ fn inner_unsafe<'a>(&'a self) -> &'a UnsafeCell<Flavor<T>> {
 /// // Let's see what that answer was
 /// println!("{:?}", rx.recv().unwrap());
 /// ```
-#[stable]
+#[stable(feature = "rust1", since = "1.0.0")]
 pub fn channel<T: Send>() -> (Sender<T>, Receiver<T>) {
     let a = Arc::new(UnsafeCell::new(oneshot::Packet::new()));
     (Sender::new(Flavor::Oneshot(a.clone())), Receiver::new(Flavor::Oneshot(a)))
@@ -514,17 +514,17 @@ pub fn channel<T: Send>() -> (Sender<T>, Receiver<T>) {
 /// let (tx, rx) = sync_channel(1);
 ///
 /// // this returns immediately
-/// tx.send(1i).unwrap();
+/// tx.send(1).unwrap();
 ///
 /// Thread::spawn(move|| {
 ///     // this will block until the previous message has been received
-///     tx.send(2i).unwrap();
+///     tx.send(2).unwrap();
 /// });
 ///
-/// assert_eq!(rx.recv().unwrap(), 1i);
-/// assert_eq!(rx.recv().unwrap(), 2i);
+/// assert_eq!(rx.recv().unwrap(), 1);
+/// assert_eq!(rx.recv().unwrap(), 2);
 /// ```
-#[stable]
+#[stable(feature = "rust1", since = "1.0.0")]
 pub fn sync_channel<T: Send>(bound: uint) -> (SyncSender<T>, Receiver<T>) {
     let a = Arc::new(UnsafeCell::new(sync::Packet::new(bound)));
     (SyncSender::new(a.clone()), Receiver::new(Flavor::Sync(a)))
@@ -562,13 +562,13 @@ fn new(inner: Flavor<T>) -> Sender<T> {
     /// let (tx, rx) = channel();
     ///
     /// // This send is always successful
-    /// tx.send(1i).unwrap();
+    /// tx.send(1).unwrap();
     ///
     /// // This send will fail because the receiver is gone
     /// drop(rx);
-    /// assert_eq!(tx.send(1i).err().unwrap().0, 1);
+    /// assert_eq!(tx.send(1).err().unwrap().0, 1);
     /// ```
-    #[stable]
+    #[stable(feature = "rust1", since = "1.0.0")]
     pub fn send(&self, t: T) -> Result<(), SendError<T>> {
         let (new_inner, ret) = match *unsafe { self.inner() } {
             Flavor::Oneshot(ref p) => {
@@ -615,7 +615,7 @@ pub fn send(&self, t: T) -> Result<(), SendError<T>> {
     }
 }
 
-#[stable]
+#[stable(feature = "rust1", since = "1.0.0")]
 impl<T: Send> Clone for Sender<T> {
     fn clone(&self) -> Sender<T> {
         let (packet, sleeper, guard) = match *unsafe { self.inner() } {
@@ -661,7 +661,7 @@ fn clone(&self) -> Sender<T> {
 }
 
 #[unsafe_destructor]
-#[stable]
+#[stable(feature = "rust1", since = "1.0.0")]
 impl<T: Send> Drop for Sender<T> {
     fn drop(&mut self) {
         match *unsafe { self.inner_mut() } {
@@ -696,7 +696,7 @@ fn new(inner: Arc<UnsafeCell<sync::Packet<T>>>) -> SyncSender<T> {
     /// This function will never panic, but it may return `Err` if the
     /// `Receiver` has disconnected and is no longer able to receive
     /// information.
-    #[stable]
+    #[stable(feature = "rust1", since = "1.0.0")]
     pub fn send(&self, t: T) -> Result<(), SendError<T>> {
         unsafe { (*self.inner.get()).send(t).map_err(SendError) }
     }
@@ -710,13 +710,13 @@ pub fn send(&self, t: T) -> Result<(), SendError<T>> {
     ///
     /// See `SyncSender::send` for notes about guarantees of whether the
     /// receiver has received the data or not if this function is successful.
-    #[stable]
+    #[stable(feature = "rust1", since = "1.0.0")]
     pub fn try_send(&self, t: T) -> Result<(), TrySendError<T>> {
         unsafe { (*self.inner.get()).try_send(t) }
     }
 }
 
-#[stable]
+#[stable(feature = "rust1", since = "1.0.0")]
 impl<T: Send> Clone for SyncSender<T> {
     fn clone(&self) -> SyncSender<T> {
         unsafe { (*self.inner.get()).clone_chan(); }
@@ -725,7 +725,7 @@ fn clone(&self) -> SyncSender<T> {
 }
 
 #[unsafe_destructor]
-#[stable]
+#[stable(feature = "rust1", since = "1.0.0")]
 impl<T: Send> Drop for SyncSender<T> {
     fn drop(&mut self) {
         unsafe { (*self.inner.get()).drop_chan(); }
@@ -749,7 +749,7 @@ fn new(inner: Flavor<T>) -> Receiver<T> {
     ///
     /// This is useful for a flavor of "optimistic check" before deciding to
     /// block on a receiver.
-    #[stable]
+    #[stable(feature = "rust1", since = "1.0.0")]
     pub fn try_recv(&self) -> Result<T, TryRecvError> {
         loop {
             let new_port = match *unsafe { self.inner() } {
@@ -810,7 +810,7 @@ pub fn try_recv(&self) -> Result<T, TryRecvError> {
     /// If the corresponding `Sender` has disconnected, or it disconnects while
     /// this call is blocking, this call will wake up and return `Err` to
     /// indicate that no more messages can ever be received on this channel.
-    #[stable]
+    #[stable(feature = "rust1", since = "1.0.0")]
     pub fn recv(&self) -> Result<T, RecvError> {
         loop {
             let new_port = match *unsafe { self.inner() } {
@@ -849,7 +849,7 @@ pub fn recv(&self) -> Result<T, RecvError> {
 
     /// Returns an iterator that will block waiting for messages, but never
     /// `panic!`. It will return `None` when the channel has hung up.
-    #[stable]
+    #[stable(feature = "rust1", since = "1.0.0")]
     pub fn iter(&self) -> Iter<T> {
         Iter { rx: self }
     }
@@ -941,7 +941,7 @@ fn abort_selection(&self) -> bool {
     }
 }
 
-#[stable]
+#[stable(feature = "rust1", since = "1.0.0")]
 impl<'a, T: Send> Iterator for Iter<'a, T> {
     type Item = T;
 
@@ -949,7 +949,7 @@ fn next(&mut self) -> Option<T> { self.rx.recv().ok() }
 }
 
 #[unsafe_destructor]
-#[stable]
+#[stable(feature = "rust1", since = "1.0.0")]
 impl<T: Send> Drop for Receiver<T> {
     fn drop(&mut self) {
         match *unsafe { self.inner_mut() } {
@@ -961,21 +961,21 @@ fn drop(&mut self) {
     }
 }
 
-#[stable]
+#[stable(feature = "rust1", since = "1.0.0")]
 impl<T> fmt::Debug for SendError<T> {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         "SendError(..)".fmt(f)
     }
 }
 
-#[stable]
+#[stable(feature = "rust1", since = "1.0.0")]
 impl<T> fmt::Display for SendError<T> {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         "sending on a closed channel".fmt(f)
     }
 }
 
-#[stable]
+#[stable(feature = "rust1", since = "1.0.0")]
 impl<T> fmt::Debug for TrySendError<T> {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         match *self {
@@ -985,7 +985,7 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
     }
 }
 
-#[stable]
+#[stable(feature = "rust1", since = "1.0.0")]
 impl<T> fmt::Display for TrySendError<T> {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         match *self {
@@ -999,14 +999,14 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
     }
 }
 
-#[stable]
+#[stable(feature = "rust1", since = "1.0.0")]
 impl fmt::Display for RecvError {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         "receiving on a closed channel".fmt(f)
     }
 }
 
-#[stable]
+#[stable(feature = "rust1", since = "1.0.0")]
 impl fmt::Display for TryRecvError {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         match *self {
@@ -1045,7 +1045,7 @@ fn smoke() {
     #[test]
     fn drop_full() {
         let (tx, _rx) = channel();
-        tx.send(box 1i).unwrap();
+        tx.send(box 1).unwrap();
     }
 
     #[test]
@@ -1053,7 +1053,7 @@ fn drop_full_shared() {
         let (tx, _rx) = channel();
         drop(tx.clone());
         drop(tx.clone());
-        tx.send(box 1i).unwrap();
+        tx.send(box 1).unwrap();
     }
 
     #[test]
@@ -1147,9 +1147,9 @@ fn chan_gone_concurrent() {
     fn stress() {
         let (tx, rx) = channel::<int>();
         let t = Thread::scoped(move|| {
-            for _ in range(0u, 10000) { tx.send(1i).unwrap(); }
+            for _ in 0u..10000 { tx.send(1).unwrap(); }
         });
-        for _ in range(0u, 10000) {
+        for _ in 0u..10000 {
             assert_eq!(rx.recv().unwrap(), 1);
         }
         t.join().ok().unwrap();
@@ -1162,7 +1162,7 @@ fn stress_shared() {
         let (tx, rx) = channel::<int>();
 
         let t = Thread::scoped(move|| {
-            for _ in range(0, AMT * NTHREADS) {
+            for _ in 0..AMT * NTHREADS {
                 assert_eq!(rx.recv().unwrap(), 1);
             }
             match rx.try_recv() {
@@ -1171,10 +1171,10 @@ fn stress_shared() {
             }
         });
 
-        for _ in range(0, NTHREADS) {
+        for _ in 0..NTHREADS {
             let tx = tx.clone();
             Thread::spawn(move|| {
-                for _ in range(0, AMT) { tx.send(1).unwrap(); }
+                for _ in 0..AMT { tx.send(1).unwrap(); }
             });
         }
         drop(tx);
@@ -1187,13 +1187,13 @@ fn send_from_outside_runtime() {
         let (tx2, rx2) = channel::<int>();
         let t1 = Thread::scoped(move|| {
             tx1.send(()).unwrap();
-            for _ in range(0i, 40) {
+            for _ in 0..40 {
                 assert_eq!(rx2.recv().unwrap(), 1);
             }
         });
         rx1.recv().unwrap();
         let t2 = Thread::scoped(move|| {
-            for _ in range(0i, 40) {
+            for _ in 0..40 {
                 tx2.send(1).unwrap();
             }
         });
@@ -1205,11 +1205,11 @@ fn send_from_outside_runtime() {
     fn recv_from_outside_runtime() {
         let (tx, rx) = channel::<int>();
         let t = Thread::scoped(move|| {
-            for _ in range(0i, 40) {
+            for _ in 0..40 {
                 assert_eq!(rx.recv().unwrap(), 1);
             }
         });
-        for _ in range(0u, 40) {
+        for _ in 0u..40 {
             tx.send(1).unwrap();
         }
         t.join().ok().unwrap();
@@ -1346,7 +1346,7 @@ fn oneshot_multi_task_recv_then_close() {
 
     #[test]
     fn oneshot_multi_thread_close_stress() {
-        for _ in range(0, stress_factor()) {
+        for _ in 0..stress_factor() {
             let (tx, rx) = channel::<int>();
             let _t = Thread::spawn(move|| {
                 drop(rx);
@@ -1357,7 +1357,7 @@ fn oneshot_multi_thread_close_stress() {
 
     #[test]
     fn oneshot_multi_thread_send_close_stress() {
-        for _ in range(0, stress_factor()) {
+        for _ in 0..stress_factor() {
             let (tx, rx) = channel::<int>();
             let _t = Thread::spawn(move|| {
                 drop(rx);
@@ -1370,7 +1370,7 @@ fn oneshot_multi_thread_send_close_stress() {
 
     #[test]
     fn oneshot_multi_thread_recv_close_stress() {
-        for _ in range(0, stress_factor()) {
+        for _ in 0..stress_factor() {
             let (tx, rx) = channel::<int>();
             Thread::spawn(move|| {
                 let res = Thread::scoped(move|| {
@@ -1388,18 +1388,18 @@ fn oneshot_multi_thread_recv_close_stress() {
 
     #[test]
     fn oneshot_multi_thread_send_recv_stress() {
-        for _ in range(0, stress_factor()) {
+        for _ in 0..stress_factor() {
             let (tx, rx) = channel();
             let _t = Thread::spawn(move|| {
-                tx.send(box 10i).unwrap();
+                tx.send(box 10).unwrap();
             });
-            assert!(rx.recv().unwrap() == box 10i);
+            assert!(rx.recv().unwrap() == box 10);
         }
     }
 
     #[test]
     fn stream_send_recv_stress() {
-        for _ in range(0, stress_factor()) {
+        for _ in 0..stress_factor() {
             let (tx, rx) = channel();
 
             send(tx, 0);
@@ -1429,22 +1429,22 @@ fn recv(rx: Receiver<Box<int>>, i: int) {
     fn recv_a_lot() {
         // Regression test that we don't run out of stack in scheduler context
         let (tx, rx) = channel();
-        for _ in range(0i, 10000) { tx.send(()).unwrap(); }
-        for _ in range(0i, 10000) { rx.recv().unwrap(); }
+        for _ in 0..10000 { tx.send(()).unwrap(); }
+        for _ in 0..10000 { rx.recv().unwrap(); }
     }
 
     #[test]
     fn shared_chan_stress() {
         let (tx, rx) = channel();
         let total = stress_factor() + 100;
-        for _ in range(0, total) {
+        for _ in 0..total {
             let tx = tx.clone();
             Thread::spawn(move|| {
                 tx.send(()).unwrap();
             });
         }
 
-        for _ in range(0, total) {
+        for _ in 0..total {
             rx.recv().unwrap();
         }
     }
@@ -1530,7 +1530,7 @@ fn destroy_upgraded_shared_port_when_sender_still_active() {
             tx2.send(()).unwrap();
         });
         // make sure the other task has gone to sleep
-        for _ in range(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();
@@ -1567,7 +1567,7 @@ fn smoke() {
     #[test]
     fn drop_full() {
         let (tx, _rx) = sync_channel(1);
-        tx.send(box 1i).unwrap();
+        tx.send(box 1).unwrap();
     }
 
     #[test]
@@ -1654,9 +1654,9 @@ fn chan_gone_concurrent() {
     fn stress() {
         let (tx, rx) = sync_channel::<int>(0);
         Thread::spawn(move|| {
-            for _ in range(0u, 10000) { tx.send(1).unwrap(); }
+            for _ in 0u..10000 { tx.send(1).unwrap(); }
         });
-        for _ in range(0u, 10000) {
+        for _ in 0u..10000 {
             assert_eq!(rx.recv().unwrap(), 1);
         }
     }
@@ -1669,7 +1669,7 @@ fn stress_shared() {
         let (dtx, drx) = sync_channel::<()>(0);
 
         Thread::spawn(move|| {
-            for _ in range(0, AMT * NTHREADS) {
+            for _ in 0..AMT * NTHREADS {
                 assert_eq!(rx.recv().unwrap(), 1);
             }
             match rx.try_recv() {
@@ -1679,10 +1679,10 @@ fn stress_shared() {
             dtx.send(()).unwrap();
         });
 
-        for _ in range(0, NTHREADS) {
+        for _ in 0..NTHREADS {
             let tx = tx.clone();
             Thread::spawn(move|| {
-                for _ in range(0, AMT) { tx.send(1).unwrap(); }
+                for _ in 0..AMT { tx.send(1).unwrap(); }
             });
         }
         drop(tx);
@@ -1810,7 +1810,7 @@ fn oneshot_multi_task_recv_then_close() {
 
     #[test]
     fn oneshot_multi_thread_close_stress() {
-        for _ in range(0, stress_factor()) {
+        for _ in 0..stress_factor() {
             let (tx, rx) = sync_channel::<int>(0);
             let _t = Thread::spawn(move|| {
                 drop(rx);
@@ -1821,7 +1821,7 @@ fn oneshot_multi_thread_close_stress() {
 
     #[test]
     fn oneshot_multi_thread_send_close_stress() {
-        for _ in range(0, stress_factor()) {
+        for _ in 0..stress_factor() {
             let (tx, rx) = sync_channel::<int>(0);
             let _t = Thread::spawn(move|| {
                 drop(rx);
@@ -1834,7 +1834,7 @@ fn oneshot_multi_thread_send_close_stress() {
 
     #[test]
     fn oneshot_multi_thread_recv_close_stress() {
-        for _ in range(0, stress_factor()) {
+        for _ in 0..stress_factor() {
             let (tx, rx) = sync_channel::<int>(0);
             let _t = Thread::spawn(move|| {
                 let res = Thread::scoped(move|| {
@@ -1852,18 +1852,18 @@ fn oneshot_multi_thread_recv_close_stress() {
 
     #[test]
     fn oneshot_multi_thread_send_recv_stress() {
-        for _ in range(0, stress_factor()) {
+        for _ in 0..stress_factor() {
             let (tx, rx) = sync_channel::<Box<int>>(0);
             let _t = Thread::spawn(move|| {
-                tx.send(box 10i).unwrap();
+                tx.send(box 10).unwrap();
             });
-            assert!(rx.recv().unwrap() == box 10i);
+            assert!(rx.recv().unwrap() == box 10);
         }
     }
 
     #[test]
     fn stream_send_recv_stress() {
-        for _ in range(0, stress_factor()) {
+        for _ in 0..stress_factor() {
             let (tx, rx) = sync_channel::<Box<int>>(0);
 
             send(tx, 0);
@@ -1893,22 +1893,22 @@ fn recv(rx: Receiver<Box<int>>, i: int) {
     fn recv_a_lot() {
         // Regression test that we don't run out of stack in scheduler context
         let (tx, rx) = sync_channel(10000);
-        for _ in range(0u, 10000) { tx.send(()).unwrap(); }
-        for _ in range(0u, 10000) { rx.recv().unwrap(); }
+        for _ in 0u..10000 { tx.send(()).unwrap(); }
+        for _ in 0u..10000 { rx.recv().unwrap(); }
     }
 
     #[test]
     fn shared_chan_stress() {
         let (tx, rx) = sync_channel(0);
         let total = stress_factor() + 100;
-        for _ in range(0, total) {
+        for _ in 0..total {
             let tx = tx.clone();
             Thread::spawn(move|| {
                 tx.send(()).unwrap();
             });
         }
 
-        for _ in range(0, total) {
+        for _ in 0..total {
             rx.recv().unwrap();
         }
     }
@@ -1994,7 +1994,7 @@ fn destroy_upgraded_shared_port_when_sender_still_active() {
             tx2.send(()).unwrap();
         });
         // make sure the other task has gone to sleep
-        for _ in range(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();
@@ -2082,7 +2082,7 @@ fn repro() {
             rx2.recv().unwrap();
         }
 
-        for _ in range(0u, 100) {
+        for _ in 0u..100 {
             repro()
         }
     }