-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Tracking Issue for Mutex::unlock() #81872
Comments
Add Mutex::unlock Tracking issue: rust-lang#81872 Discussion: rust-lang#79434 (comment) r? `@m-ou-se`
I don't think this needs to require |
I can make a PR for that... |
Move Mutex::unlock to T: ?Sized r? `@mbrubeck` cc rust-lang#81872
Move Mutex::unlock to T: ?Sized r? ``@mbrubeck`` cc rust-lang#81872
A bit pedantic, but wouldn't it make sense for the drop impl for |
|
Ah right, that is problematic. |
The |
Any progress on this? Wondering why it's still pending... |
Mainly, I think this is lacking manpower to drive it forward... |
What needs to be done to get this into stable? |
My own inclination is to not accept this. It seems likely to cause folks to use this when it would just be better to let drop handle it. It's idiomatic for drop to deal with these sorts of things IMO, and I'm not convinced that the self-documenting nature of this method is enough to motivate setting a precedent for this. Curious to hear what the rest of the team thinks. @rfcbot fcp close |
Team member @BurntSushi has proposed to close this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
@BurntSushi Reading back on the thread, I realize the motivation is not really discussed. I have a very particular use cases in mind. I agree that normally, it should be idiomatic to just let the lock drop by going out of scope. However, there are cases when this is not preferable, and currently one must call
Anyway, I hope that's useful. |
Yeah that all makes sense. I'm just not sure it's worth adding an explicit |
@BurntSushi Do those cases have performance or correctness implications? I guess RefCell could have an analogous problem to deadlocks. I guess I'm arguing that locks are significantly more common to have to manually drop than the others and that the impact is significantly more difficult to debug, as to make it deserve some special treatment. (That might be entirely because of the types of projects I work on, though).
I'm intrigued. What kind of efforts are you thinking of? How do you see manual drop being improved? I'm open to other solutions. |
FWIW I like this method. I implemented |
Relevant zulip thread https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/stabilizing.20Mutex.3A.3Aunlock.28.29 It was brought up there that maybe some closure-based API ( I have to agree with that sentiment, especially since many times you only need to run one or two statements while a mutex is locked. Encouraging use of a closure to perform small-scoped operations seems like very idiomatic Rust. Having a wrapper around an existing public API that doesn't add new functionality - less so. |
@tgross35 I do think that a closure-based interface like that can be useful, but it also has some big limitations:
|
Yeah, there are of course problems and I see it was discussed in #81873. My point was moreso just that I don't think it would make sense to have both this and a (RFC reviewed) closure method, since they kind of target similar use cases. And for the remaining 15% of cases, For what it's worth on rightward drift with >1 mutex, I think most cases could get by sharing the scope of the first mutex. mtx1.with_lock(|guard1| {
let guard2 = mtx2.lock().unwrap();
let guard3 = mtx3.lock().unwrap();
}); // lock it all back up |
See #61976 for a previous attempt to add |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
The final comment period, with a disposition to close, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. |
Add block-based mutex unlocking example This modifies the existing example in the Mutex docs to show both `drop()` and block based early unlocking. Alternative to rust-lang#81872, which is getting closed.
…-mutex-unlock, r=jhpratt Remove `Mutex::unlock` Function As of the completion of the FCP in rust-lang#81872 (comment), it has come to the conclusion to be closed. This PR removes the function entirely in light of the above. Closes rust-lang#81872.
…-mutex-unlock, r=jhpratt Remove `Mutex::unlock` Function As of the completion of the FCP in rust-lang#81872 (comment), it has come to the conclusion to be closed. This PR removes the function entirely in light of the above. Closes rust-lang#81872.
…-mutex-unlock, r=jhpratt Remove `Mutex::unlock` Function As of the completion of the FCP in rust-lang#81872 (comment), it has come to the conclusion to be closed. This PR removes the function entirely in light of the above. Closes rust-lang#81872.
…-mutex-unlock, r=jhpratt Remove `Mutex::unlock` Function As of the completion of the FCP in rust-lang#81872 (comment), it has come to the conclusion to be closed. This PR removes the function entirely in light of the above. Closes rust-lang#81872.
…-mutex-unlock, r=jhpratt Remove `Mutex::unlock` Function As of the completion of the FCP in rust-lang#81872 (comment), it has come to the conclusion to be closed. This PR removes the function entirely in light of the above. Closes rust-lang#81872.
…-mutex-unlock, r=jhpratt Remove `Mutex::unlock` Function As of the completion of the FCP in rust-lang#81872 (comment), it has come to the conclusion to be closed. This PR removes the function entirely in light of the above. Closes rust-lang#81872.
Rollup merge of rust-lang#121736 - HTGAzureX1212:HTGAzureX1212/remove-mutex-unlock, r=jhpratt Remove `Mutex::unlock` Function As of the completion of the FCP in rust-lang#81872 (comment), it has come to the conclusion to be closed. This PR removes the function entirely in light of the above. Closes rust-lang#81872.
Feature gate:
#![feature(mutex_unlock)]
This is a tracking issue for the
Mutex::unlock
function. The goal of this function is to replacedrop(mutex_guard)
which doesn't clear express that a synchronization event is occurring.Some earlier discussion, including a previous implementation: #79434 (comment)
Public API
Steps / History
Unresolved Questions
RwLock
? It would be a bit more complicated.The text was updated successfully, but these errors were encountered: