Skip to content

Commit

Permalink
add a simple example for thread::current()
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-piziak committed Aug 25, 2016
1 parent 528c6f3 commit cf8e1fe
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/libstd/thread/mod.rs
Expand Up @@ -322,6 +322,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 cf8e1fe

Please sign in to comment.