Code Monkey home page Code Monkey logo

Comments (10)

ticki avatar ticki commented on July 19, 2024

@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?

from parking_lot.

Amanieu avatar Amanieu commented on July 19, 2024

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)

from parking_lot.

ticki avatar ticki commented on July 19, 2024

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.

from parking_lot.

Amanieu avatar Amanieu commented on July 19, 2024

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.

from parking_lot.

ticki avatar ticki commented on July 19, 2024

cc. @alexcrichton

cc. @nikomatsakis

from parking_lot.

ticki avatar ticki commented on July 19, 2024

Maybe they have something to add.

from parking_lot.

nikomatsakis avatar nikomatsakis commented on July 19, 2024

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?

from parking_lot.

alexcrichton avatar alexcrichton commented on July 19, 2024

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

from parking_lot.

Amanieu avatar Amanieu commented on July 19, 2024

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

from parking_lot.

ticki avatar ticki commented on July 19, 2024

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

from parking_lot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.