-
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
Tracking Issue for rwlock_downgrade
#128203
Comments
For the When a call to So a solution that is arguably less wrong would be to allow readers who have just been waken up after a call to It is hard to say if this is a good solution, if anyone would like to give their input that would be much appreciated! |
@joboet Hi, I saw that you wrote the |
Sure! There are two cases to consider:
The fast path is pretty easy, you just need to CAS the write-locked state ( For the contended case, I'd first of all change this line: rust/library/std/src/sys/sync/rwlock/queue.rs Lines 340 to 344 in 2d5a628
so that the count is one if the lock is write-locked (try If the fast path above fails, you need to try to acquire the queue lock so that you can make modifications to the queue (try a CAS that sets the If you acquired the |
I think I understand your algorithm, though I was wondering if there might be another way to do it. This algorithm basically is an atomic unlock and place a reader node at the end of the queue, right? Do you think it is possible to implement I'm not sure this is possible, but if it is, it would allow for more opportunities to potentially wake up readers as well. |
I see the problem now after playing around with the code and trying to implement what I said above. In the queue implementation, if there are any waiters in the queue (writer or readers), we do not allow readers to take the read lock. So my idea of waking up readers after a call to downgrade is not exactly compatible with the current implementation. However, that doesn't imply that this is completely impossible with the current implementation. I think what might work is forcing the writer who just downgraded to wake up the next readers in the queue AND remove them from the queue. Maybe the former writer thread can set a bit somewhere (probably stored in the @joboet Do you have any thoughts about this? (Sorry for all of the pings!) (EDIT: resolved! see PR) |
Rwlock downgrade Tracking Issue: rust-lang#128203 This PR adds a `downgrade` method for `RwLock` / `RwLockWriteGuard` on all currently supported platforms. Outstanding questions: - [ ] Does the `futex.rs` change affect performance at all? It doesn't seem like it will but we can't be certain until we bench it... - [ ] Should the SOLID platform implementation [be ported over](rust-lang#128219 (comment)) to the `queue.rs` implementation to allow it to support downgrades?
…oss35 Rwlock downgrade Tracking Issue: rust-lang#128203 This PR adds a `downgrade` method for `RwLock` / `RwLockWriteGuard` on all currently supported platforms. Outstanding questions: - [x] Does the `futex.rs` change affect performance at all? It doesn't seem like it will but we can't be certain until we bench it... - [ ] Should the SOLID platform implementation [be ported over](rust-lang#128219 (comment)) to the `queue.rs` implementation to allow it to support downgrades?
…oss35 Rwlock downgrade Tracking Issue: rust-lang#128203 This PR adds a `downgrade` method for `RwLock` / `RwLockWriteGuard` on all currently supported platforms. Outstanding questions: - [x] Does the `futex.rs` change affect performance at all? It doesn't seem like it will but we can't be certain until we bench it... - [x] Should the SOLID platform implementation [be ported over](rust-lang#128219 (comment)) to the `queue.rs` implementation to allow it to support downgrades?
…oss35 Rwlock downgrade Tracking Issue: rust-lang#128203 This PR adds a `downgrade` method for `RwLock` / `RwLockWriteGuard` on all currently supported platforms. Outstanding questions: - [x] Does the `futex.rs` change affect performance at all? It doesn't seem like it will but we can't be certain until we bench it... - [x] Should the SOLID platform implementation [be ported over](rust-lang#128219 (comment)) to the `queue.rs` implementation to allow it to support downgrades?
…oss35 Rwlock downgrade Tracking Issue: rust-lang#128203 This PR adds a `downgrade` method for `RwLock` / `RwLockWriteGuard` on all currently supported platforms. Outstanding questions: - [x] ~~Does the `futex.rs` change affect performance at all? It doesn't seem like it will but we can't be certain until we bench it...~~ - [x] ~~Should the SOLID platform implementation [be ported over](rust-lang#128219 (comment)) to the `queue.rs` implementation to allow it to support downgrades?~~
…oss35 Rwlock downgrade Tracking Issue: rust-lang#128203 This PR adds a `downgrade` method for `RwLock` / `RwLockWriteGuard` on all currently supported platforms. Outstanding questions: - [x] ~~Does the `futex.rs` change affect performance at all? It doesn't seem like it will but we can't be certain until we bench it...~~ - [x] ~~Should the SOLID platform implementation [be ported over](rust-lang#128219 (comment)) to the `queue.rs` implementation to allow it to support downgrades?~~
…oss35 Rwlock downgrade Tracking Issue: rust-lang#128203 This PR adds a `downgrade` method for `RwLock` / `RwLockWriteGuard` on all currently supported platforms. Outstanding questions: - [x] ~~Does the `futex.rs` change affect performance at all? It doesn't seem like it will but we can't be certain until we bench it...~~ - [x] ~~Should the SOLID platform implementation [be ported over](rust-lang#128219 (comment)) to the `queue.rs` implementation to allow it to support downgrades?~~
Feature gate:
#![feature(rwlock_downgrade)]
This is a tracking issue for a
downgrade
method forRwLock
as discussed in rust-lang/libs-team#392.The
downgrade
method onRwLockWriteGuard
will transform a write-lockedRwLock
into a read-locked one.Public API
Steps / History
RwLock
downgrade
method libs-team#392downgrade
implementation forfutex.rs
downgrade
implementation forno_threads.rs
downgrade
implementation forqueue.rs
downgrade
implementation forsolid.rs
downgrade
implementation forteeos.rs
Unresolved Questions
How to go about implementingdowngrade
for thequeue.rs
implementation?Does thesolid_asp3
platform already have adowngrade
method on theirRwLock
implementation?Does lock poisoning play into this at all?Footnotes
https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html ↩
The text was updated successfully, but these errors were encountered: