From da100fe0bb7ba77dbcc346018068dbfdba053f6b Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Tue, 23 May 2017 19:02:23 -0700 Subject: Support VS 2017 Fixes #38584 --- src/libstd/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/libstd') diff --git a/src/libstd/Cargo.toml b/src/libstd/Cargo.toml index 717892be2ab..e17918506fe 100644 --- a/src/libstd/Cargo.toml +++ b/src/libstd/Cargo.toml @@ -35,7 +35,7 @@ rustc_tsan = { path = "../librustc_tsan" } [build-dependencies] build_helper = { path = "../build_helper" } -gcc = "0.3.27" +gcc = "0.3.50" [features] backtrace = [] -- cgit 1.4.1-3-g733a5 From d3f3e26db04c91e80bce8fa022b535d79cfe5c6c Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Fri, 2 Jun 2017 00:18:53 -0400 Subject: Rewrite `Receiver::iter` doc example to show resulting values. --- src/libstd/sync/mpsc/mod.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/sync/mpsc/mod.rs b/src/libstd/sync/mpsc/mod.rs index 40b3e789ce4..8fdd99e86b0 100644 --- a/src/libstd/sync/mpsc/mod.rs +++ b/src/libstd/sync/mpsc/mod.rs @@ -1370,14 +1370,16 @@ impl Receiver { /// let (send, recv) = channel(); /// /// thread::spawn(move || { - /// send.send(1u8).unwrap(); - /// send.send(2u8).unwrap(); - /// send.send(3u8).unwrap(); + /// send.send(1).unwrap(); + /// send.send(2).unwrap(); + /// send.send(3).unwrap(); /// }); /// - /// for x in recv.iter() { - /// println!("Got: {}", x); - /// } + /// let mut iter = recv.iter(); + /// assert_eq!(iter.next(), Some(1)); + /// assert_eq!(iter.next(), Some(2)); + /// assert_eq!(iter.next(), Some(3)); + /// assert_eq!(iter.next(), None); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn iter(&self) -> Iter { -- cgit 1.4.1-3-g733a5 From eb48ee72dba6646d92fb06e384d396759ff80f59 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Fri, 2 Jun 2017 00:20:25 -0400 Subject: Rewrite `Receiver::try_iter` doc example to show resulting values. --- src/libstd/sync/mpsc/mod.rs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/sync/mpsc/mod.rs b/src/libstd/sync/mpsc/mod.rs index 8fdd99e86b0..7d5e1929cd2 100644 --- a/src/libstd/sync/mpsc/mod.rs +++ b/src/libstd/sync/mpsc/mod.rs @@ -1395,29 +1395,34 @@ impl Receiver { /// /// # Examples /// - /// ```rust + /// ```no_run /// use std::sync::mpsc::channel; /// use std::thread; /// use std::time::Duration; /// /// let (sender, receiver) = channel(); /// - /// // Nothing is in the buffer yet + /// // nothing is in the buffer yet /// assert!(receiver.try_iter().next().is_none()); - /// println!("Nothing in the buffer..."); /// /// thread::spawn(move || { + /// thread::sleep(Duration::from_secs(1)); /// sender.send(1).unwrap(); /// sender.send(2).unwrap(); /// sender.send(3).unwrap(); /// }); /// - /// println!("Going to sleep..."); - /// thread::sleep(Duration::from_secs(2)); // block for two seconds + /// // nothing is in the buffer yet + /// assert!(receiver.try_iter().next().is_none()); /// - /// for x in receiver.try_iter() { - /// println!("Got: {}", x); - /// } + /// // block for two seconds + /// thread::sleep(Duration::from_secs(2)); + /// + /// let mut iter = receiver.try_iter(); + /// assert_eq!(iter.next(), Some(1)); + /// assert_eq!(iter.next(), Some(2)); + /// assert_eq!(iter.next(), Some(3)); + /// assert_eq!(iter.next(), None); /// ``` #[stable(feature = "receiver_try_iter", since = "1.15.0")] pub fn try_iter(&self) -> TryIter { -- cgit 1.4.1-3-g733a5 From b76b9e1467f97d9f156da1773728c30ca5fd019a Mon Sep 17 00:00:00 2001 From: Felix Raimundo Date: Sat, 13 May 2017 21:19:13 +0200 Subject: Expands `detach` documentation in `thread::JoinHande`. Part of #29378 . - Adds an example of a thread detaching. - Expands what `detaching` means. --- src/libstd/thread/mod.rs | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index 200368be275..c1cee58c5eb 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -1019,11 +1019,12 @@ impl JoinInner { /// An owned permission to join on a thread (block on its termination). /// -/// A `JoinHandle` *detaches* the child thread when it is dropped. +/// A `JoinHandle` *detaches* the associated thread when it is dropped, which +/// means that there is no longer any handle to thread and no way to `join` +/// on it. /// /// Due to platform restrictions, it is not possible to [`Clone`] this -/// handle: the ability to join a child thread is a uniquely-owned -/// permission. +/// handle: the ability to join a thread is a uniquely-owned permission. /// /// This `struct` is created by the [`thread::spawn`] function and the /// [`thread::Builder::spawn`] method. @@ -1052,6 +1053,30 @@ impl JoinInner { /// }).unwrap(); /// ``` /// +/// Child being detached and outliving its parent: +/// +/// ```no_run +/// use std::thread; +/// use std::time::Duration; +/// +/// let original_thread = thread::spawn(|| { +/// let _detached_thread = thread::spawn(|| { +/// // Here we sleep to make sure that the first thread returns before. +/// thread::sleep(Duration::from_millis(10)); +/// // This will be called, even though the JoinHandle is dropped. +/// println!("♫ Still alive ♫"); +/// }); +/// }); +/// +/// let _ = original_thread.join(); +/// println!("Original thread is joined."); +/// +/// // We make sure that the new thread has time to run, before the main +/// // thread returns. +/// +/// thread::sleep(Duration::from_millis(1000)); +/// ``` +/// /// [`Clone`]: ../../std/clone/trait.Clone.html /// [`thread::spawn`]: fn.spawn.html /// [`thread::Builder::spawn`]: struct.Builder.html#method.spawn -- cgit 1.4.1-3-g733a5