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

Make MutexGuard Send? #99613

Closed
smessmer opened this issue Jul 22, 2022 · 4 comments
Closed

Make MutexGuard Send? #99613

smessmer opened this issue Jul 22, 2022 · 4 comments
Labels
A-concurrency Area: Concurrency 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

@smessmer
Copy link

Since Rust 1.62 has a new Mutex implementation that doesn't use pthread anymore, can we now mark MutexGuard as Send?

@bjorn3
Copy link
Member

bjorn3 commented Jul 22, 2022

We still use pthreads as fallback for platforms where futex based Mutexes are not yet implemented:

mod pthread_mutex;
mod pthread_rwlock;
mod pthread_condvar;
pub(crate) use pthread_mutex::{Mutex, MovableMutex};
pub(crate) use pthread_rwlock::{RwLock, MovableRwLock};
pub(crate) use pthread_condvar::MovableCondvar;

@bjorn3 bjorn3 added the C-feature-request Category: A feature request, i.e: not implemented / a PR. label Jul 22, 2022
@RalfJung
Copy link
Member

AFAIK the plan is to keep using pthreads on macOS. This means MutexGuard cannot be made Send on all tier 1 platforms. I doubt we want this to be a per-platform thing.

@thomcc thomcc added A-concurrency Area: Concurrency T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Jul 23, 2022
@thomcc
Copy link
Member

thomcc commented Jul 23, 2022

I believe we could do this if we decided to implement usync-style locks based around thread parking. This has been discussed at one point but has various drawbacks, and I'm unsure if it's still on the table.

In general I don't think we should do this. It's reasonable for the OS to want to know which thread holds a lock, in order to be able to implement various schemes in its scheduler. I think this probably has more utility than the utility of being able to send mutexguards to other threads, and so we'd probably be better off leaving the option open of using locks that allow this, by not codifying it in our API.

Parking lot supports this behind the send_guard feature btw, so if you really need it you can get it by adding a dependency.

@Dylan-DPC
Copy link
Member

Closing this as it has drawbacks as mentioned above and wouldn't be accepted and there are alternatives available

@Dylan-DPC Dylan-DPC closed this as not planned Won't fix, can't repro, duplicate, stale Feb 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-concurrency Area: Concurrency 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

5 participants