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

RwLock: support upgrades and downgrades #69240

Closed
d-e-s-o opened this issue Feb 17, 2020 · 8 comments
Closed

RwLock: support upgrades and downgrades #69240

d-e-s-o opened this issue Feb 17, 2020 · 8 comments
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@d-e-s-o
Copy link
Contributor

d-e-s-o commented Feb 17, 2020

I think it would be great (certainly useful for me) if RwLock were to support read-write upgrades and write-read downgrades. Currently I don't see a way to accomplish the same and I always have to get write access over the entire operation.

parking_lot currently supports both cases (here & here). I also understand that there exists a proposal to use parking_lot as the lock implementation backend.

Once (if) that lands, it should merely be a matter of extending the std APIs to provide such support.

@jonas-schievink jonas-schievink added C-feature-request Category: A feature request, i.e: not implemented / a PR. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Feb 17, 2020
@sfackler
Copy link
Member

Even though we want to move the internals to parking_lot, that's an implementation detail. I don't think we'd want to expand the API beyond what pthreads provides.

@d-e-s-o
Copy link
Contributor Author

d-e-s-o commented Feb 17, 2020

Why?

@sfackler
Copy link
Member

It would prohibit us from backing synchronization primitives with pthreads.

@d-e-s-o
Copy link
Contributor Author

d-e-s-o commented Feb 17, 2020

Correct me if I am wrong (I am not familiar with the implementation), but we could always implement our own set of synchronization primitives and, in fact, that seems to be what the switch to parking lot seems to be about.

Part of the reason for that switch seems to lie in the subtleties and "weird" behaviors of the OS specific APIs. I'd go so far to fudge pthreads into this category and just ignore it to the degree possible instead of lifting it to some form of gold standard (that's not exactly what you are saying, but to me it almost amounts to the same thing, because everything extending the limited API surface they have is ignored).

I'd argue that it is reasonable for a reader-writer lock in the standard library to provide support for such functionality. It's not that an upgrade/downgrade can be emulated easily (at least I am not aware of a way). As such, it can be seen essential (if only in some and not all cases) to write the most performant code -- which I understand is what Rust aims to enable.

@sfackler
Copy link
Member

pthreads is not a gold standard, it is a least common denominator. The standard library does not intend to provide arbitrarily obscure functionality.

I disagree that these operations are "essential" - C# is the only language that I'm aware of that offers them as part of its standard library.

@Dylan-DPC
Copy link
Member

Closing this as it is not intended and can be considered implementation details based on the discussion above

@Dylan-DPC Dylan-DPC closed this as not planned Won't fix, can't repro, duplicate, stale Dec 19, 2023
@oxalica
Copy link
Contributor

oxalica commented Mar 4, 2024

I don't think we'd want to expand the API beyond what pthreads provides.

Since #93740, we are no longer limited by functionalities provided by pthreads. Could we revisit this feature request?

@ChrisDenton
Copy link
Member

Nowadays your best bet would to open an API Change Proposal (ACP) that sketches the API you'd like and explains the motivation for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants