diff options
| author | bors <bors@rust-lang.org> | 2017-01-01 22:45:02 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-01-01 22:45:02 +0000 |
| commit | 07191e2b11b4f9f0328470b5af13d4765085ff6a (patch) | |
| tree | a2a7a18fe000223af4b8d2767fdd5ca0ce58a9b3 /src/libstd/thread | |
| parent | 917e5baae7ff931b13a8b40d2fce60395fefe7a4 (diff) | |
| parent | 3312febf22794bb9451410e5950b9c970d77004d (diff) | |
| download | rust-07191e2b11b4f9f0328470b5af13d4765085ff6a.tar.gz rust-07191e2b11b4f9f0328470b5af13d4765085ff6a.zip | |
Auto merge of #38548 - GuillaumeGomez:thread_struct_docs, r=frewsxcv
Add missing example for Thread struct r? @frewsxcv
Diffstat (limited to 'src/libstd/thread')
| -rw-r--r-- | src/libstd/thread/mod.rs | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index 81979fd41a6..a2039db0e40 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -648,6 +648,23 @@ pub fn park_timeout(dur: Duration) { /// A `ThreadId` is an opaque object that has a unique value for each thread /// that creates one. `ThreadId`s do not correspond to a thread's system- /// designated identifier. +/// +/// # Examples +/// +/// ``` +/// #![feature(thread_id)] +/// +/// use std::thread; +/// +/// let handler = thread::Builder::new() +/// .spawn(|| { +/// let thread = thread::current(); +/// let thread_id = thread.id(); +/// }) +/// .unwrap(); +/// +/// handler.join().unwrap(); +/// ``` #[unstable(feature = "thread_id", issue = "21507")] #[derive(Eq, PartialEq, Copy, Clone)] pub struct ThreadId(u64); @@ -700,6 +717,22 @@ struct Inner { #[derive(Clone)] #[stable(feature = "rust1", since = "1.0.0")] /// A handle to a thread. +/// +/// # Examples +/// +/// ``` +/// use std::thread; +/// +/// let handler = thread::Builder::new() +/// .name("foo".into()) +/// .spawn(|| { +/// let thread = thread::current(); +/// println!("thread name: {}", thread.name().unwrap()); +/// }) +/// .unwrap(); +/// +/// handler.join().unwrap(); +/// ``` pub struct Thread { inner: Arc<Inner>, } @@ -723,6 +756,21 @@ impl Thread { /// Atomically makes the handle's token available if it is not already. /// /// See the module doc for more detail. + /// + /// # Examples + /// + /// ``` + /// use std::thread; + /// + /// let handler = thread::Builder::new() + /// .spawn(|| { + /// let thread = thread::current(); + /// thread.unpark(); + /// }) + /// .unwrap(); + /// + /// handler.join().unwrap(); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn unpark(&self) { let mut guard = self.inner.lock.lock().unwrap(); @@ -733,6 +781,23 @@ impl Thread { } /// Gets the thread's unique identifier. + /// + /// # Examples + /// + /// ``` + /// #![feature(thread_id)] + /// + /// use std::thread; + /// + /// let handler = thread::Builder::new() + /// .spawn(|| { + /// let thread = thread::current(); + /// println!("thread id: {:?}", thread.id()); + /// }) + /// .unwrap(); + /// + /// handler.join().unwrap(); + /// ``` #[unstable(feature = "thread_id", issue = "21507")] pub fn id(&self) -> ThreadId { self.inner.id |
