diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2016-12-22 16:50:34 +0100 |
|---|---|---|
| committer | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2016-12-31 13:10:44 +0100 |
| commit | 3312febf22794bb9451410e5950b9c970d77004d (patch) | |
| tree | d4f2bd4608541e21d2969b5bcc213c110b6fe487 /src/libstd/thread | |
| parent | 1b38776c1f68c6fd47c1b2f7b7974efc7dd64901 (diff) | |
| download | rust-3312febf22794bb9451410e5950b9c970d77004d.tar.gz rust-3312febf22794bb9451410e5950b9c970d77004d.zip | |
Add missing example for Thread struct
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 2a3fb5ec43f..6a11385a1e5 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -558,6 +558,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); @@ -610,6 +627,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>, } @@ -633,6 +666,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(); @@ -643,6 +691,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 |
