Comments (10)
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.
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.
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.
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.
cc. @alexcrichton
cc. @nikomatsakis
from parking_lot.
Maybe they have something to add.
from parking_lot.
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.
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.
I'm closing this issue since it seems to be outside the scope of parking_lot
.
from parking_lot.
You're right. I'll make a crate for this.
from parking_lot.
Related Issues (20)
- lock_api: `RwLockReadGuard::unlocked` incorrectly claims fairness
- Doesn't require what glue? HOT 1
- Time for a new parking_lot_core release? HOT 1
- `ReentrantMutex::bump()` probably needs to adjust the `lock_count`
- Panic in Linux thread_parker HOT 3
- Fail to upgrade a upgradable read lock twice in a scope
- Consider enabling deadlock_detection in docs.rs builds
- Update README claims HOT 1
- Weird error when passing guards to another thread HOT 5
- INIT constrains which types can be used to implement RawMutex HOT 8
- Why does `notify_one_slow` return true even if threads were only requeued, and not unparked? HOT 2
- Panic when dropping `RwLockUpgradableReadGuard` after using `with_upgraded` HOT 2
- Allow indirect/partially owned mapping HOT 1
- Migrate to `safer_owning_ref` HOT 2
- RawMutex moving. HOT 1
- typo: Release date on CHANGELOG for parking_lot_core 0.9.9 and lock_api 0.4.11 is wrong
- Sorry for issue, is unic way to comunicate with you, please remove after. thanks
- Mutex performance drop in case of cache contention
- Update documentation of differences between `parking_lot::Mutex` and `std::sync::Mutex`
- Fail to `upgrade` an `ArcRwLockUpgradableReadGuard` twice
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from parking_lot.