-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Happens-before relationship between wake and poll #128920
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
Comments
It's certainly not a safety requirement. If the runtime forgets to poll a future, that's not going to result in UB. But I would say that it's a reasonable logical requirement. If you call |
I think the question is not "must the executor poll the future?" (it will not do this if future is dropped, for example), but "must the |
I meant, UB if runtime polled but did not establish happens-before relationship |
I mean, it's definitely not UB to call It's just ... when you call |
Yes, that's the basic principle of making progress in async tasks. The problem is the details of what this means in multi-threaded conditions, when the If the executor (that is, the thing which implements Lack of it must not cause UB, of course — the future may not rely on the executor‘s behavior for memory safety, since I was confused about this myself, and the URLO thread previously linked now contains clarification. |
Not establishing happens-before relationship can lead to deadlock, for example:
Deadlock is sound though. So maybe mention in RawWakerVTable invariants that not providing happens-before relationship can lead to deadlock? |
Should it be also mentioned, that executor does not need to do any additional synchronization with LocalWaker? Because they are in one thread, so no need for potentially expensive Release/Acquire operations on the executor site? |
Things happening on the same thread automatically have happens before relationships. No need for us to special case that. |
From
So there actually is a guarantee, that task would get polled after wake. Can it be modified to say that "there will be at least one poll with happens-before relationship to wake"? That will also rule out concerns about parallel polling and waking, as those are "ignored" by the rule |
I think the wording would be more clear if we say:
which has the same manner as we have done in the document of |
Sounds solid. I'll make a PR then. It looks like a breaking change for me, not sure... |
Maybe, we should adjust the order to make the wording formal, see #132892, the change should be:
|
Location
Probably here https://doc.rust-lang.org/std/task/struct.RawWakerVTable.html
Summary
Is it safety invariant of executor to provide happens-before relationship between wake and poll? If not, is it a logical one? Or futures must not rely on that? But if there is no happens-before relationship, then data might be missed.
Related discussion: https://users.rust-lang.org/t/must-async-executor-provide-happens-before-relationship/114861?u=ddystopia
There are opposite answers that indicates that community is not really sure what is the answer to that question.
Also related discord question with answer in favor of requiring happens-before relationship
The text was updated successfully, but these errors were encountered: