-
Notifications
You must be signed in to change notification settings - Fork 4
The trait should be redesigned to be a better fit for intended use cases #12
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
Comments
I think this should be done as an update to the RFC (https://github.com/rust-embedded/wg/blob/master/rfcs/0377-mutex-trait.md) to get proper frame of mind and comparison. |
@jonas-schievink I don't quite understand what you mean here. I feel that the trait should support both interior mutability as well as Send and Sync. Is that what you're saying as well? |
@PTaylor-FluenTech I'm not really sure yet. The issue is that the trait doesn't allow implementations without interior mutability. I don't know if that's a problem, as I haven't yet looked into the use cases this trait is supposed to enable. |
@jonas-schievink I may be using the wrong terminology. I think the fact that a mutable borrow is required means the mutex is not providing interior mutability of the data it is holding. |
Since the trait has to be implemented for (yeah, this is fairly confusing) |
Yeah, I think the necessary implementation of the trait for a reference seems to be a source of much difficulty. I know it was for me. So is the solution to make |
Indeed, they're part of it. Not sure how to solve it yet (do we need 2 traits? are use cases that even benefit from a trait as opposed to inherent methods fine with an implicit |
Just as an example, this is the trait I've settled on in pub trait BusMutex {
type Bus;
fn create(v: Self::Bus) -> Self;
fn lock<R, F: FnOnce(&mut Self::Bus) -> R>(&self, f: F) -> R;
} (The |
After publishing the initial version, I noticed a few things:
&SomeMutex
, which means you can still deadlock. This also makes the lock method hard to call.Send
dataSync
" aspect, leading to expensive implementations (eg. Added arch specific mutex implementation cortex-m#209). Since we already have plenty of data structures like cells for interior mutability, it is more important to cover the "makingSend
dataSync
" part.I'm not yet sure how the trait should look, and what it would take to make it still useful for RTFM etc., but I think the current design is not optimal.
The text was updated successfully, but these errors were encountered: