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

Tracking issue for reentrant mutexes #27738

Closed
alexcrichton opened this issue Aug 12, 2015 · 11 comments
Closed

Tracking issue for reentrant mutexes #27738

alexcrichton opened this issue Aug 12, 2015 · 11 comments
Labels
B-unstable Blocker: Implemented in the nightly compiler and unstable. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@alexcrichton
Copy link
Member

This is a tracking issue for the unstable reentrant_mutex feature in the standard library. Currently this flavor of mutex is not exposed at all in the standard library (it's private in the sysmodule), but it's an often-useful form of a mutex.

We should decide whether or not the standard library will expose this flavor of mutex and then ensure that the API is audited for conventions, naming, and performance.

cc @nagisa

@alexcrichton alexcrichton added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. B-unstable Blocker: Implemented in the nightly compiler and unstable. labels Aug 12, 2015
@nagisa
Copy link
Member

nagisa commented Aug 12, 2015

I’m still a bit uncomfortable by the fact that we do not allow inner mutability in this particular Mutex. You’d usually won’t want to Mutex-guard immutable data because it is, well, immutable and in most cases is already MT-safe, and mutable ReentrantMutex ready to share and use looks a little bit odd/redundant: Arc<ReentrantMutex<RefCell<T>>>.

@arielb1
Copy link
Contributor

arielb1 commented Aug 12, 2015

@nagisa

The idea of ReentrantMutex is to allow accessing a big multi-Cell (and/or RefCell) context-structure from multiple threads. This would be kind-of broken by making it return &mut

@Diggsey
Copy link
Contributor

Diggsey commented Aug 12, 2015

@nagisa RwLock already does pretty much what you're suggesting anyway? ReentrantMutex fills a gap in the standard library: taking something !Sync, and making it Sync, with as little overhead as possible.

@alexcrichton
Copy link
Member Author

This type isn't actually exposed from the standard library, I believe I just mistakenly read the unstable tag, so closing.

@nox
Copy link
Contributor

nox commented Aug 10, 2016

Can we reopen this? We are going to need this in Servo for exactly the reason @Diggsey mentioned.

Cc @asajeffrey.

@asajeffrey
Copy link

I ended up reimplementing the interface on top of regular mutexes https://github.com/servo/servo/blob/master/components/util/remutex.rs. The main use case is data structures that are reentrant but not thread-safe, and use interior mutability. In our case that was IPC channels, but you can do similar examples with cells.

@alexcrichton
Copy link
Member Author

Note that this was never an exported interface of the standard library, so we'd probably require an RFC to add this feature to the standard library

@asajeffrey
Copy link

Given that reentrant mutexes can be implemented on top of stdlib's mutexes, should they be in std or a crate? One argument for putting them in std would be if there's an efficiency gain from using native reentrant mutexes.

@nox
Copy link
Contributor

nox commented Aug 11, 2016

Given the stdlib's reentrant mutexes AFAIK aren't implemented on top of Mutex and they already live in there, I would rather write an RFC and just expose them.

@ckaran
Copy link

ckaran commented Apr 9, 2021

Well, it's been about 4.5 years, can we look at this again?

@SimonSapin
Copy link
Contributor

This thread can be informative for historical context but it is marked as closed, let’s discuss in #58612.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
B-unstable Blocker: Implemented in the nightly compiler and unstable. 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

8 participants