Skip to content
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

Merged
merged 1 commit into from
Apr 5, 2017

Conversation

GuillaumeGomez
Copy link
Member

Fixes #40176.

r? @steveklabnik
cc @rust-lang/docs

/// 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.
Copy link
Contributor

@ScottAbbey ScottAbbey Mar 17, 2017

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.

Copy link
Member

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.
Copy link
Contributor

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?

Copy link

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.

Copy link
Contributor

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?

Copy link

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". 😃

Copy link
Member Author

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.

Copy link

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.

@frewsxcv
Copy link
Member

cc @rust-lang/libs for terminology here

@alexcrichton
Copy link
Member

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!)

@ScottAbbey
Copy link
Contributor

ScottAbbey commented Mar 19, 2017

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 Mutex object. By changing all references of "mutex" to "lock", the problem only got worse, now we are talking about locking and unlocking the lock.

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:

When a thread locks a mutex, it becomes the owner of that mutex. Only the mutex owner can unlock the mutex.

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:

When a thread acquires a lock, it becomes the holder of that lock. Only the lock owner can unlock the mutex.

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 is_poisoned:

/// Determines whether the lock is poisoned
...
/// panic!(); // the mutex gets poisoned

The first one and several other "lock is poisoned" references should instead say "the mutex".

This phrase appears many times:

/// If another user of this mutex panicked while holding the lock, then this call will return an error instead.

I think all of those should be changed back to "while holding the mutex".

Under struct Mutex<T>:

to ensure that the native mutex is used correctly we box the inner lock...

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.

@steveklabnik
Copy link
Member

agree wholeheartedly with @ScottAbbey

@steveklabnik
Copy link
Member

@GuillaumeGomez ping! any updates on this?

@GuillaumeGomez
Copy link
Member Author

I need to update it. Will do it in the day.

@GuillaumeGomez
Copy link
Member Author

Ok so I made a first update. Did I miss anything?

Copy link
Member

@steveklabnik steveklabnik left a 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

@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the inverse

@@ -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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

///
/// 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

/// 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same on both lines

/// 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

@GuillaumeGomez
Copy link
Member Author

I updated to @steveklabnik's comments.

@steveklabnik
Copy link
Member

@bors: r+ rollup

@bors
Copy link
Contributor

bors commented Apr 3, 2017

📌 Commit e7c2160 has been approved by steveklabnik

frewsxcv added a commit to frewsxcv/rust that referenced this pull request Apr 3, 2017
…ncy, r=steveklabnik

Fix mutex's docs inconsistency

Fixes rust-lang#40176.

r? @steveklabnik
cc @rust-lang/docs
frewsxcv added a commit to frewsxcv/rust that referenced this pull request Apr 3, 2017
…ncy, r=steveklabnik

Fix mutex's docs inconsistency

Fixes rust-lang#40176.

r? @steveklabnik
cc @rust-lang/docs
frewsxcv added a commit to frewsxcv/rust that referenced this pull request Apr 4, 2017
…ncy, r=steveklabnik

Fix mutex's docs inconsistency

Fixes rust-lang#40176.

r? @steveklabnik
cc @rust-lang/docs
frewsxcv added a commit to frewsxcv/rust that referenced this pull request Apr 4, 2017
…ncy, r=steveklabnik

Fix mutex's docs inconsistency

Fixes rust-lang#40176.

r? @steveklabnik
cc @rust-lang/docs
frewsxcv added a commit to frewsxcv/rust that referenced this pull request Apr 5, 2017
…ncy, r=steveklabnik

Fix mutex's docs inconsistency

Fixes rust-lang#40176.

r? @steveklabnik
cc @rust-lang/docs
frewsxcv added a commit to frewsxcv/rust that referenced this pull request Apr 5, 2017
…ncy, r=steveklabnik

Fix mutex's docs inconsistency

Fixes rust-lang#40176.

r? @steveklabnik
cc @rust-lang/docs
bors added a commit that referenced this pull request Apr 5, 2017
@bors bors merged commit e7c2160 into rust-lang:master Apr 5, 2017
@GuillaumeGomez GuillaumeGomez deleted the mutex-doc-inconsistency branch April 5, 2017 21:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants