-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Fix mutex's docs inconsistency #40608
Conversation
src/libstd/sync/mutex.rs
Outdated
/// held. An RAII guard is returned to allow scoped unlock of the lock. When | ||
/// the guard goes out of scope, the mutex will be unlocked. | ||
/// the guard goes out of scope, the mutex's lock will be unlocked. |
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.
the mutex's lock will be unlocked.
I'm not sure this change is an improvement over the original. Shouldn't it match the language used in line 27:
ever accessed when the mutex is locked.
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.
I agree - a mutex doesn't contain a lock, it is a lock, IMO.
@@ -183,18 +183,18 @@ impl<T: ?Sized> Mutex<T> { | |||
/// Acquires a mutex, blocking the current thread until it is able to do so. |
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.
Acquires a mutex, blocking
Two lines after this, the comment speaks of acquiring "the lock," should this instance be modified as well?
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.
Concern here: "lock" is generic, while "mutex" is shorthand for "mutually exclusive lock" and therefore seems most specific and correct to me.
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.
This is the same paragraph directly quoted in #40176, would you say it would have been better to change the one instance of "the lock" to "the mutex" instead of the other way around?
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.
Yes "lock" or "acquire" as the verb, and "mutex" as the noun. Therefore "the mutex" makes more sense than "the lock". 😃
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.
I agree with @ScottAbbey on this one. For non-english speaker, acquiring a lock better than acquiring a mutex which doesn't mean much.
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.
@GuillaumeGomez while I agree, this isn't just pros. We're discussing technical documentation and as such should be as specific as possible, without being exclusionary.
If we're going with the general term, then we need to the MSDN thing of explaining that the lock is exclusive and will block any threads that attempt to acquire the lock while the lock is held.
IMO this gets verbose, but does have the advantage of being very approachable and lends itself well to education as well as to translation.
48b5389
to
713600a
Compare
cc @rust-lang/libs for terminology here |
I personally consider "mutex" and "lock" as interchangeable, but canonicalizing on one seems fine (e.g. they're interchangeable, so doesn't matter what we call it!) |
I agree with @whoisj, almost every reference to "lock" should instead be "mutex." The language that seems to make the most sense is: The mutex may be locked or unlocked. The original complaint in #40176 was that the lock and the mutex were both used to refer to the Searching for some other published writing about a similar topic, I found the following in Chapter 30 (page 634) of The Linux Programming Interface, by Michael Kerrisk:
I find this short quote easy to read and understand. Rewriting that sentence to fit the state of this mutex documentation as it currently stands, we would have something like:
This is still in the same confusing state we started with. Shouldn't the thread acquire (or lock) "the mutex", be the holder (or owner) of "the mutex", and "the mutex holder (or owner)" be able to unlock it? There are still some consistency issues. In the comment for
The first one and several other "lock is poisoned" references should instead say "the mutex". This phrase appears many times:
I think all of those should be changed back to "while holding the mutex". Under
Should be "the inner mutex". I don't trust myself to try writing any of this as I really don't know what I'm talking about anyway. |
agree wholeheartedly with @ScottAbbey |
@GuillaumeGomez ping! any updates on this? |
I need to update it. Will do it in the day. |
713600a
to
2167948
Compare
Ok so I made a first update. Did I miss anything? |
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.
a couple more spots, then r=me
src/libstd/sync/mutex.rs
Outdated
@@ -92,7 +92,7 @@ use sys_common::poison::{self, TryLockError, TryLockResult, LockResult}; | |||
/// let lock2 = lock.clone(); | |||
/// | |||
/// let _ = thread::spawn(move || -> () { | |||
/// // This thread will acquire the mutex first, unwrapping the result of | |||
/// // This thread will acquire the lock first, unwrapping the result of |
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.
this is the inverse
src/libstd/sync/mutex.rs
Outdated
@@ -180,10 +180,10 @@ impl<T> Mutex<T> { | |||
} | |||
|
|||
impl<T: ?Sized> Mutex<T> { | |||
/// Acquires a mutex, blocking the current thread until it is able to do so. | |||
/// Acquires a lock, blocking the current thread until it is able to do so. |
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.
same
src/libstd/sync/mutex.rs
Outdated
/// | ||
/// This function will block the local thread until it is available to acquire | ||
/// the mutex. Upon returning, the thread is the only thread with the mutex | ||
/// the lock. Upon returning, the thread is the only thread with the lock |
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.
same
src/libstd/sync/mutex.rs
Outdated
/// If another user of this mutex panicked while holding the mutex, then | ||
/// this call will return an error once the mutex is acquired. | ||
/// If another user of this mutex panicked while holding the lock, then | ||
/// this call will return an error once the lock is acquired. |
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.
same on both lines
src/libstd/sync/mutex.rs
Outdated
/// If another user of this mutex panicked while holding the mutex, then | ||
/// this call will return failure if the mutex would otherwise be | ||
/// If another user of this mutex panicked while holding the lock, then | ||
/// this call will return failure if the lock would otherwise be |
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.
same
2167948
to
e7c2160
Compare
I updated to @steveklabnik's comments. |
@bors: r+ rollup |
📌 Commit e7c2160 has been approved by |
…ncy, r=steveklabnik Fix mutex's docs inconsistency Fixes rust-lang#40176. r? @steveklabnik cc @rust-lang/docs
…ncy, r=steveklabnik Fix mutex's docs inconsistency Fixes rust-lang#40176. r? @steveklabnik cc @rust-lang/docs
…ncy, r=steveklabnik Fix mutex's docs inconsistency Fixes rust-lang#40176. r? @steveklabnik cc @rust-lang/docs
…ncy, r=steveklabnik Fix mutex's docs inconsistency Fixes rust-lang#40176. r? @steveklabnik cc @rust-lang/docs
…ncy, r=steveklabnik Fix mutex's docs inconsistency Fixes rust-lang#40176. r? @steveklabnik cc @rust-lang/docs
…ncy, r=steveklabnik Fix mutex's docs inconsistency Fixes rust-lang#40176. r? @steveklabnik cc @rust-lang/docs
Fixes #40176.
r? @steveklabnik
cc @rust-lang/docs