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

Mappable lock guards #10

Closed
Ogeon opened this issue Aug 16, 2016 · 6 comments
Closed

Mappable lock guards #10

Ogeon opened this issue Aug 16, 2016 · 6 comments

Comments

@Ogeon
Copy link

Ogeon commented Aug 16, 2016

Would it be possible to implement a map method on (some of) the lock guards? There has been talks about it being unsound for some implementations of Mutex, particularly the one in the standard library, but there are ways to do it and it's a very useful feature. Do you think it would work with your particular implementation?

@Amanieu
Copy link
Owner

Amanieu commented Aug 16, 2016

Unfortunately, the safety hole with Condvar still applies to my implementation. It's a fundamental limitation of the interface.

It might be possible to implement this using a separate MappableMutexGuard type which wraps a MutexGuard and prevents it from being used with a Condvar, but I'm not sure if the lifetimes work out.

@Ogeon
Copy link
Author

Ogeon commented Aug 16, 2016

That's too bad, but I suppose a MappeableMutexGuard wouldn't be too bad if the lifetime works out. It's how it's done in https://github.com/reem/rust-shared-mutex, possibly for a similar reason. I know practically nothing about this, myself, which is why I'm asking, but it would be cool to have.

I have this scenario where I want quite fast access to data that I want to transform before returning it, to avoid excessive dynamic checks. It would be nice to have a lock that is as light as possible, and part of the reason is that my data structure will usually have to be double locked (once for the whole structure and then for occasional inner mutability of each containing item). The other part of it is just pure speed. I don't think there's a way around that, since the inner mutability is basically a feature, and the function that uses it takes &mut self to prevent it from being called more than once. I'm specifically interested in an RwLock for this.

Anyway, this is just me wishing I could just pick features from different libraries 😄

Edit: Made some of my intentions more clear.

@Amanieu
Copy link
Owner

Amanieu commented Aug 16, 2016

Well it does sound like a nice feature to have, so I'll look into implementing it in parking_lot at some point.

@Ogeon
Copy link
Author

Ogeon commented Aug 16, 2016

That would be great 👍 My my actual usecase isn't really the best motivation, since my runtime check may actually be unnoticeably cheap (and hopefully optimized to oblivion), but it's also about convenience, since it's just the beginning of the pipeline. Users may want to keep on mapping.

I'll see what I can do in the meantime. Thanks for looking into it!

@Amanieu
Copy link
Owner

Amanieu commented Aug 30, 2016

Have you considered using owning_ref for this?

@Ogeon
Copy link
Author

Ogeon commented Aug 30, 2016

I hadn't actually, but it looks like it fulfills my needs. I'll give it a try. Thanks!

@Amanieu Amanieu closed this as completed Aug 31, 2016
therustmonk pushed a commit to therustmonk/parking_lot that referenced this issue Feb 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants