Skip to content

Commit 00645e8

Browse files
committedDec 24, 2016
Add JoinHandle missing examples
1 parent 1b38776 commit 00645e8

File tree

1 file changed

+40
-6
lines changed

1 file changed

+40
-6
lines changed
 

‎src/libstd/thread/mod.rs

+40-6
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ impl<T> JoinInner<T> {
749749
///
750750
/// A `JoinHandle` *detaches* the child thread when it is dropped.
751751
///
752-
/// Due to platform restrictions, it is not possible to `Clone` this
752+
/// Due to platform restrictions, it is not possible to [`Clone`] this
753753
/// handle: the ability to join a child thread is a uniquely-owned
754754
/// permission.
755755
///
@@ -760,7 +760,7 @@ impl<T> JoinInner<T> {
760760
///
761761
/// Creation from [`thread::spawn`]:
762762
///
763-
/// ```rust
763+
/// ```
764764
/// use std::thread;
765765
///
766766
/// let join_handle: thread::JoinHandle<_> = thread::spawn(|| {
@@ -770,7 +770,7 @@ impl<T> JoinInner<T> {
770770
///
771771
/// Creation from [`thread::Builder::spawn`]:
772772
///
773-
/// ```rust
773+
/// ```
774774
/// use std::thread;
775775
///
776776
/// let builder = thread::Builder::new();
@@ -780,22 +780,56 @@ impl<T> JoinInner<T> {
780780
/// }).unwrap();
781781
/// ```
782782
///
783+
/// [`Clone`]: ../../std/clone/trait.Clone.html
783784
/// [`thread::spawn`]: fn.spawn.html
784785
/// [`thread::Builder::spawn`]: struct.Builder.html#method.spawn
785786
#[stable(feature = "rust1", since = "1.0.0")]
786787
pub struct JoinHandle<T>(JoinInner<T>);
787788

788789
impl<T> JoinHandle<T> {
789-
/// Extracts a handle to the underlying thread
790+
/// Extracts a handle to the underlying thread.
791+
///
792+
/// # Examples
793+
///
794+
/// ```
795+
/// #![feature(thread_id)]
796+
///
797+
/// use std::thread;
798+
///
799+
/// let builder = thread::Builder::new();
800+
///
801+
/// let join_handle: thread::JoinHandle<_> = builder.spawn(|| {
802+
/// // some work here
803+
/// }).unwrap();
804+
///
805+
/// let thread = join_handle.thread();
806+
/// println!("thread id: {:?}", thread.id());
807+
/// ```
790808
#[stable(feature = "rust1", since = "1.0.0")]
791809
pub fn thread(&self) -> &Thread {
792810
&self.0.thread
793811
}
794812

795813
/// Waits for the associated thread to finish.
796814
///
797-
/// If the child thread panics, `Err` is returned with the parameter given
798-
/// to `panic`.
815+
/// If the child thread panics, [`Err`] is returned with the parameter given
816+
/// to [`panic`].
817+
///
818+
/// [`Err`]: ../../std/result/enum.Result.html#variant.Err
819+
/// [`panic!`]: ../../std/macro.panic.html
820+
///
821+
/// # Examples
822+
///
823+
/// ```
824+
/// use std::thread;
825+
///
826+
/// let builder = thread::Builder::new();
827+
///
828+
/// let join_handle: thread::JoinHandle<_> = builder.spawn(|| {
829+
/// // some work here
830+
/// }).unwrap();
831+
/// join_handle.join().expect("Couldn't join on the associated thread");
832+
/// ```
799833
#[stable(feature = "rust1", since = "1.0.0")]
800834
pub fn join(mut self) -> Result<T> {
801835
self.0.join()

0 commit comments

Comments
 (0)
Please sign in to comment.