add a simple example for thread::current()

This commit is contained in:
Matthew Piziak 2016-08-25 16:20:21 -04:00
parent 528c6f3ed6
commit cf8e1fee16

View File

@ -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 \