-
Notifications
You must be signed in to change notification settings - Fork 628
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
Add Mutex::poll_lock method #1972
Comments
Presumably this would have to return some kind of token and be paired with a You would also need to store the |
Not really. You could just accept that the task the future was running on would get a spurious wakeup.
Yeah, if you want to do something |
I think it would be ok for a specific usecase to choose to forget the token and get a spurious wakeup, but I think the general API should support it if ergonomic. |
It's not only that. It also means no other task will get woken up if it doesn't explicitely poll. The Mutex always only wakes up one I implemented a solution for a similar issue in You could potentially use the |
I think #2571 added a reasonable alternative to this. |
I just had a bug in some code that looks like this:
The bug is that the
MutexLockFuture
returned byMutex::lock
deregisters itself when it gets dropped. So if I pollMyReceiver
and the lock is held the task won't get woken up again when the lock is released. AFAICT my options for fixing this are:MutexLockFuture
insideMyReceiver
. This is inconvenient and inefficient sinceMutexLockFuture
borrows theMutex
and so I'd need to userental
and an extra layer of boxing.MyReceiver
with anasync
block/function instead of implementingFuture
directly. Again this means an extra layer of boxing. Also I'm trying to implement a low-level primitive here and I'd rather just implementFuture
directly.std
non-asyncMutex
. This is obviously less than ideal, though I know in my case the lock won't get held for very long.At the moment I've gone for option (2) since it's the laziest option, but it would be nice if there was a simple way to do this properly.
Could we add a
poll_lock
method toMutex
which allows me to use theMutex
in the buggy way I attempted above?The text was updated successfully, but these errors were encountered: