-
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
Use the parking_lot locking primitives #56410
Conversation
This comment has been minimized.
This comment has been minimized.
r? @RalfJung |
93093dc
to
57526ff
Compare
Just to be clear, this PR only changes the "back-end" of the mutex implementation. There are no changes to the public |
Isn’t there a difference between fairness of native EDIT: on some of the platforms, that is. |
Any fairness was "implementation-defined" in the current implementation. |
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.
Some observations; applies generally throughout the PR but I picked a few spots to illustrate. :)
fb5360f
to
b4d3471
Compare
This comment has been minimized.
This comment has been minimized.
b4d3471
to
e230096
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
FYI, I will not have time to look at this "+4168 −2426" PR this week. I should be able to get to it next week though. I also feel slightly overwhelmed by the importance of this and would appreciate a co-reviewer -- maybe someone who actually has reviewed libstd code before :D |
I should add that I'm currently working on improving this code. Will likely push changes in a day or two. I have already backported some of the feedback here directly to |
c62d50d
to
910670f
Compare
This comment has been minimized.
This comment has been minimized.
abc062b
to
9718fba
Compare
I could post some kind of benchmarks. The MutexBuilt using latest nightly rustc/libstd:
Built using the code currently in this PR (stage1 compiler):
RwLockBuilt using latest nightly rustc/libstd:
Built using the code currently in this PR (stage1 compiler):
All of the above was on Linux. |
9718fba
to
1407c89
Compare
This comment has been minimized.
This comment has been minimized.
I was able to remove the boxing of the inner locking type in the EDIT: Worth noting that this also affects the size of the synchronization structs. |
@KronicDeth I made a PR for some single-threaded RawMutex/RawRwLock implementations that hopefully avoid the entire parking & timers subsystems altogether. Needs heavy review. Amanieu/parking_lot#187 |
191: Add initial parking_lot_core tests r=Amanieu a=faern This library could use more tests, to be more robust. This was one of the things pointed out in the review of the integration into std in rust-lang/rust#56410 `WTF::ParkingLot` has a number of tests we can take inspiration from. And this is somewhat of a port of some of those tests. However, when I ported it 1:1 I found a race condition, so I had to implement the semaphore a bit differently. I also got away without the tests relying on a working mutex or condvar implementation. Because we can't make the `parking_lot_core` tests depend on the higher level `parking_lot`, nor do we want to depend on locking primitives in std if we aim to become the base for those implementations one day. Co-authored-by: Linus Färnstrand <[email protected]>
I am totally out of the loop on this and anyway don't have the resources for reviews as big as this, I am afraid... so I removed myself from the list of reviewers here. |
Are there chances that this PR became too outdated and big so it won't be merged at all? I just read @matklad 's article about spinloks and became really interested in getting these in std. |
The problem with this PR is not how outdated it is towards master. What is holding it back is how |
@faern how about closing this PR and reopening it once the parking lot issues are settled? Would probably be easier that way |
Easier for whom? The triage team or people trying to stay abreast of progress on this issue? |
Everyone. The author, reviewers, triagists |
@Dylan-DPC It's not like I have the time to contribute to this now nor likely soon. I feel like many of the outstanding parking_lot issues are partially out of my hands / not related to integrating parking_lot into libstd to begin with. For me personally it won't really be "easier" if this was closed. But nor would it be harder. Whenever a new PR is opened again we have to navigate back and fourth between two PR threads, but that is going to be doable. Maybe better than having a PR open forever that no one contributes towards. @jethrogb has a point about that people might want to stay up to date with this and not miss when/if it finally starts moving again. But they can still subscribe to this PR and if a new one is opened, someone can just post a comment in this PR linking to the new one. |
Yes @faern understandable. But even if kept open and it is ready to be merged, it will increase the number of conflicts this has with other prs. |
You can reopen this one at that time. |
Incidentally, on Darwin, pthread mutexes use priority inheritance, while |
Note of caution (we should have this somewhere linkable IMO, or GitHub could just make it simpler one their side): always reopen before pushing to the branch, otherwise GitHub will hide the option to reopen. However, even if you pushed, you can still recover by finding the commit the branch was previously on, and force-pushing that, which will unlock reopening the PR. |
For future readers who don't want to read through 300 comments, this is faern/parking_lot#1. |
This PR adds the
parking_lot
code as a git submodule and reimplements all the standard library locking primitives so they are thin wrappers over theparking_lot
equivalents. The standard library public API is of course kept the same.This has been discussed in https://internals.rust-lang.org/t/standard-library-synchronization-primitives-and-undefined-behavior/8439/9
Thanks @Amanieu for mentoring when doing this, and basically all the code is his as well of course.
Fixes #35836
Fixes #53127