Skip to content

Commit 23f7698

Browse files
Rollup merge of rust-lang#35997 - matthew-piziak:thread-current-example, r=GuillaumeGomez
add a simple example for `thread::current()` r? @GuillaumeGomez
2 parents 0c33197 + cf8e1fe commit 23f7698

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/libstd/thread/mod.rs

+18
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,24 @@ pub fn spawn<F, T>(f: F) -> JoinHandle<T> where
320320
}
321321

322322
/// Gets a handle to the thread that invokes it.
323+
///
324+
/// #Examples
325+
///
326+
/// Getting a handle to the current thread with `thread::current()`:
327+
///
328+
/// ```
329+
/// use std::thread;
330+
///
331+
/// let handler = thread::Builder::new()
332+
/// .name("named thread".into())
333+
/// .spawn(|| {
334+
/// let handle = thread::current();
335+
/// assert_eq!(handle.name(), Some("named thread"));
336+
/// })
337+
/// .unwrap();
338+
///
339+
/// handler.join().unwrap();
340+
/// ```
323341
#[stable(feature = "rust1", since = "1.0.0")]
324342
pub fn current() -> Thread {
325343
thread_info::current_thread().expect("use of std::thread::current() is not \

0 commit comments

Comments
 (0)