-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DOC] Improve the thread::park and thread::unpark documentation #41809
Merged
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
061b56b
Add a link to `park` in the `park_timeout` doc.
c158962
Add link to the module doc in `park_timeout`.
d9628f9
Add `park` info to `unpark`.
5573c47
Better example for `thread::unpark`.
c0d475a
fix typo
fa0cdaa
Inline `thread::park` documentation.
03c9510
Fix typos in `thread::park` documentation.
afe74c3
Fix link
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -585,16 +585,17 @@ pub fn park() { | |
/// Blocks unless or until the current thread's token is made available or | ||
/// the specified duration has been reached (may wake spuriously). | ||
/// | ||
/// The semantics of this function are equivalent to `park()` except that the | ||
/// thread will be blocked for roughly no longer than `ms`. This method | ||
/// should not be used for precise timing due to anomalies such as | ||
/// The semantics of this function are equivalent to [`park()`][[park] except | ||
/// that the thread will be blocked for roughly no longer than `dur`. This | ||
/// method should not be used for precise timing due to anomalies such as | ||
/// preemption or platform differences that may not cause the maximum | ||
/// amount of time waited to be precisely `ms` long. | ||
/// | ||
/// See the [module documentation][thread] for more detail. | ||
/// | ||
/// [thread]: index.html | ||
/// [park_timeout]: fn.park_timeout.html | ||
/// [park]: fn.park.html | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
#[rustc_deprecated(since = "1.6.0", reason = "replaced by `std::thread::park_timeout`")] | ||
pub fn park_timeout_ms(ms: u32) { | ||
|
@@ -604,13 +605,13 @@ pub fn park_timeout_ms(ms: u32) { | |
/// Blocks unless or until the current thread's token is made available or | ||
/// the specified duration has been reached (may wake spuriously). | ||
/// | ||
/// The semantics of this function are equivalent to `park()` except that the | ||
/// thread will be blocked for roughly no longer than `dur`. This method | ||
/// should not be used for precise timing due to anomalies such as | ||
/// The semantics of this function are equivalent to [`park()`][[park] except | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto. 👍 |
||
/// that the thread will be blocked for roughly no longer than `dur`. This | ||
/// method should not be used for precise timing due to anomalies such as | ||
/// preemption or platform differences that may not cause the maximum | ||
/// amount of time waited to be precisely `dur` long. | ||
/// | ||
/// See the module doc for more detail. | ||
/// See the [module doc][thread] for more detail. | ||
/// | ||
/// # Platform behavior | ||
/// | ||
|
@@ -635,6 +636,9 @@ pub fn park_timeout_ms(ms: u32) { | |
/// park_timeout(timeout); | ||
/// } | ||
/// ``` | ||
/// | ||
/// [thread]: index.html | ||
/// [park]: fn.park.html | ||
#[stable(feature = "park_timeout", since = "1.4.0")] | ||
pub fn park_timeout(dur: Duration) { | ||
let thread = current(); | ||
|
@@ -764,22 +768,36 @@ impl Thread { | |
|
||
/// Atomically makes the handle's token available if it is not already. | ||
/// | ||
/// See the module doc for more detail. | ||
/// Every thread is equipped with some basic low-level blocking support, via | ||
/// the [`park()`][park] function and the `unpark()` method. These can be | ||
/// used as a more CPU-efficient implementation of a spinlock. | ||
/// | ||
/// See the [module doc][thread] for more detail. | ||
/// | ||
/// # Examples | ||
/// | ||
/// ``` | ||
/// use std::thread; | ||
/// | ||
/// let handler = thread::Builder::new() | ||
/// let parked_thread = thread::Builder::new() | ||
/// .spawn(|| { | ||
/// let thread = thread::current(); | ||
/// thread.unpark(); | ||
/// println!("Parking thread"); | ||
/// thread::park(); | ||
/// println!("Thread unparked"); | ||
/// }) | ||
/// .unwrap(); | ||
/// | ||
/// handler.join().unwrap(); | ||
/// // Let some time pass for the thread to be spawned. | ||
/// thread::sleep(Duration::from_millis(10)); | ||
/// | ||
/// println!("Unpark the thread"); | ||
/// parked_thread.thread().unpark(); | ||
/// | ||
/// parked_thread.join().unwrap(); | ||
/// ``` | ||
/// | ||
/// [thread]: index.html | ||
/// [park]: fn.park.html | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
pub fn unpark(&self) { | ||
let mut guard = self.inner.lock.lock().unwrap(); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Too many
[
here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks :)