Skip to content

Fix RwLock::try_write #25153

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

Merged
merged 2 commits into from
May 6, 2015
Merged

Fix RwLock::try_write #25153

merged 2 commits into from
May 6, 2015

Conversation

jgallagher
Copy link

Previously, try_write actually only obtained shared read access (but would return a RwLockWriteGuard if that access was successful).

Also updates the docs for try_read and try_write, which were leftover from when those methods returned Option instead of Result.

@rust-highfive
Copy link
Contributor

r? @brson

(rust_highfive has picked a reviewer for you, use r? to override)

@brson brson added the beta-nominated Nominated for backporting to the compiler in the beta channel. label May 6, 2015
@brson
Copy link
Contributor

brson commented May 6, 2015

Nominating for beta by request of the author.

///
/// If the access could not be granted at this time, then `Err` is returned.
/// Otherwise, an RAII guard is returned which will release the shared access
/// when it is dropped.
Copy link
Member

Choose a reason for hiding this comment

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

I believe that a poisoned rwlock will also return an Err even if it was successful in the try_read, so technically the lock could be locked if Err is returned. Perhaps the docs could be updated slightly to account for this?

Copy link
Author

Choose a reason for hiding this comment

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

I think the pre-existing Failure section covers this, but it's outside the diff of this PR (https://github.com/jgallagher/rust/blob/rwlock-try-write/src/libstd/sync/rwlock.rs#L187-L190). Is what it states incorrect, or should this paragraph be reworded to include it somehow?

Copy link
Member

Choose a reason for hiding this comment

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

Hm ok so upon re-reading my original though that this indicates Err means the lock wasn't grabbed isn't quite right, it just means that if it couldn't be grabbed Err is returned, so looks good to me!

@alexcrichton
Copy link
Member

Nice catch @jgallagher! Just one small nit from me on the doc updates and otherwise this is good to go.

@alexcrichton
Copy link
Member

@bors: r+ 833fc27 p=10

bors added a commit that referenced this pull request May 6, 2015
Previously, `try_write` actually only obtained shared read access (but would return a `RwLockWriteGuard` if that access was successful).

Also updates the docs for `try_read` and `try_write`, which were leftover from when those methods returned `Option` instead of `Result`.
@bors
Copy link
Collaborator

bors commented May 6, 2015

⌛ Testing commit 833fc27 with merge e6378cb...

@bors bors merged commit 833fc27 into rust-lang:master May 6, 2015
@jgallagher jgallagher deleted the rwlock-try-write branch May 6, 2015 20:59
@alexcrichton alexcrichton added the beta-accepted Accepted for backporting to the compiler in the beta channel. label May 7, 2015
@brson brson removed the beta-nominated Nominated for backporting to the compiler in the beta channel. label May 8, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beta-accepted Accepted for backporting to the compiler in the beta channel.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants