-
Notifications
You must be signed in to change notification settings - Fork 847
Await completed Tasks on the same thread. #11142
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
Conversation
Fixes dotnet#9685. Besides passing ExecuteSynchronously, if the task is already completed, the continuation is directly invoked, bypassing Task.ContinueWith. Such trick is also performed by Roslyn.
d3d263e to
f753263
Compare
dsyme
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One minor change requestedremoving a comment
|
@teo-tsirpanis This caused a regression, see #11797. The change here installs a new trampoline on each completed task continuation - no new trampoline should be installed when we detect synchronous completion. I'll push a PR with the fix |
|
It looks like this PR causes other problems beyond #11797, through the use of ExecuteSynchronously clag on this line: https://github.com/dotnet/fsharp/pull/11142/files#diff-7330c080710da91733bbc5e1b5bdae30f4adf528f7847efbac3d86a0d4132b1dR945 I will remove that, this flag is not necessary for the asynchronous case, since we are already checking for synchronous completion. |
This PR fixes #9685 by both setting a
TaskContinuationFlags.RunSynchronouslywhen attaching a continuation on theTasks and by avoiding setting the continuation altogether when the task is completed.The issue's title's "never" is now changed to "only when there is no sufficient stack", in which case the trampoline will take over.
Finally, the PR uses
Thread.IsThreadPoolThreadin one occasion it should.