Skip to content

Commit

Permalink
Rollup merge of rust-lang#35997 - matthew-piziak:thread-current-examp…
Browse files Browse the repository at this point in the history
…le, r=GuillaumeGomez

add a simple example for `thread::current()`

r? @GuillaumeGomez
  • Loading branch information
GuillaumeGomez committed Aug 30, 2016
2 parents cce337f + cf8e1fe commit 2535f69
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/libstd/thread/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,24 @@ pub fn spawn<F, T>(f: F) -> JoinHandle<T> where
}

/// Gets a handle to the thread that invokes it.
///
/// #Examples
///
/// Getting a handle to the current thread with `thread::current()`:
///
/// ```
/// use std::thread;
///
/// let handler = thread::Builder::new()
/// .name("named thread".into())
/// .spawn(|| {
/// let handle = thread::current();
/// assert_eq!(handle.name(), Some("named thread"));
/// })
/// .unwrap();
///
/// handler.join().unwrap();
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn current() -> Thread {
thread_info::current_thread().expect("use of std::thread::current() is not \
Expand Down

0 comments on commit 2535f69

Please sign in to comment.