Skip to content

Conversation

@teo-tsirpanis
Copy link
Contributor

This PR fixes #9685 by both setting a TaskContinuationFlags.RunSynchronously when attaching a continuation on the Tasks 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.IsThreadPoolThread in one occasion it should.

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.
Copy link
Contributor

@dsyme dsyme left a 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

@dsyme
Copy link
Contributor

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
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Awaiting completed Task with Async never runs on only one thread

4 participants