Uh oh!
There was an error while loading. Please reload this page.
Await completed Tasks on the same thread. - #11142
Conversation
Fixesdotnet#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.
Uh oh!
There was an error while loading. Please reload this page.
dsyme
left a comment
There was a problem hiding this comment.
One minor change requestedremoving a comment
dsyme
commented
Jul 8, 2021
@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 |
dsyme
commented
Jul 21, 2021
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.