-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix waker behavior when invoked before a
poll
finishes
It's possible for a task's waker to be invoked in the middle of a call to that task's `poll` by the executor. We had accounted for that possibility if the task called *its own* waker, but that's not good enough: the waker can escape to other threads that can invoke it before `poll` finishes (e.g., if the task blocks to acquire a lock). This change fixes the waker behavior by clarifying the semantics of a call to `wake`: a task whose waker is invoked should not be blocked *when it next returns Pending to the executor*, and should be woken if that has already happened. To do this, we introduce a new `Sleeping` state for tasks, that has the same semantics as `Blocked` but that is recognized by waker invocations, which will only unblock a task in `Sleeping` state. This also removes the special case "woken by self" behavior -- being woken by *any* thread should be enough to trigger this sleep logic.
- Loading branch information
1 parent
31f169d
commit 74e7fa9
Showing
6 changed files
with
155 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters