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

futures integration #24

Closed
ticki opened this issue Feb 26, 2017 · 10 comments
Closed

futures integration #24

ticki opened this issue Feb 26, 2017 · 10 comments

Comments

@ticki
Copy link

ticki commented Feb 26, 2017

No description provided.

@ticki
Copy link
Author

ticki commented Feb 26, 2017

@Amanieu

I've played a bit around with this here (only mutex so far), but I'm running into a pretty interesting issue: I cannot rely on looping try_lock, because they're not guaranteed to fall so they are available at some point when fetched.

I think a possible solution is to make use of another flag in mutexes, which essentially says "you can't someone else is currently using this mutex, so you cannot directly acquire it after it is unlocked", but even that seems pretty messy.

What I'm thinking is some method that called in Mutex::async_lock() to ensure that MutexFuture::poll() will return Ok(futures::Async::Ready(x)) at some point. That is, the mutex is "reserved" for the future.

I guess it is sufficient with a method on RawMutex, but what and how? Is a new bitflag in the state needed?

Any thoughts?

@Amanieu
Copy link
Owner

Amanieu commented Feb 26, 2017

Integrating support for futures seems to be quite a bit more involved than just calling try_lock in poll. The poll implementation also needs to call task::park to get a Task object which must be unparked when the mutex is released.

(though do correct me if I'm wrong, I'm not an expert on futures)

@ticki
Copy link
Author

ticki commented Feb 26, 2017

No, it's right. That was what I was trying to say: While my approach might work, it doesn't have to, and it is likely pretty slow if the mutex is locked all the time.

@Amanieu
Copy link
Owner

Amanieu commented Feb 26, 2017

I think that implementing support for this would require pretty extensive modifications to the parking_lot_core mechanism. I think that you would be better off implementing a new Mutex type from scratch in a separate library.

@ticki
Copy link
Author

ticki commented Feb 26, 2017

cc. @alexcrichton

cc. @nikomatsakis

@ticki
Copy link
Author

ticki commented Feb 26, 2017

Maybe they have something to add.

@nikomatsakis
Copy link

I'm not really sure what the goals are with this issue. @ticki what exactly do you mean by "futures integration"? Maybe sketch out some use cases?

@alexcrichton
Copy link
Contributor

Yes I think we'd have to drill into what "futures integration" even means in this context to be able to add something.

@Amanieu
Copy link
Owner

Amanieu commented Mar 6, 2017

I'm closing this issue since it seems to be outside the scope of parking_lot.

@Amanieu Amanieu closed this as completed Mar 6, 2017
@ticki
Copy link
Author

ticki commented Mar 6, 2017

You're right. I'll make a crate for this.

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

4 participants