Force secondary await continuations to run asynchronously (#25280)
authorStephen Toub <stoub@microsoft.com>
Mon, 24 Jun 2019 13:27:47 +0000 (09:27 -0400)
committerGitHub <noreply@github.com>
Mon, 24 Jun 2019 13:27:47 +0000 (09:27 -0400)
commitd58a283f2a69da1509b8d76dfec0959b93e061c8
treeb9f5a98f43b058d193bc2cab6ff1826ae4c9e496
parent8974a699899bdc2cc5687504e1ada606ac803e9b
Force secondary await continuations to run asynchronously (#25280)

* Force secondary await continuations to run asynchronously

For performance reasons, await continuations have been invoked synchronously, meaning they're invoked as part of the antecedent task's completion (as long as that task allows it, as long as there's sufficient stack space, etc.)  This generally works out well in the case where there's a single await continuation, which is far and away the common case.  However, it can cause problems in situations where there are multiple await continuations, as those continuations will end up being serialized, which can lead to slowdowns and deadlocks in niche situations.  To address that, this commit backs off a bit.  The first await continuation is still invoked synchronously, but subsequent await continuations are invoked asynchronously, such that they are not blocked by a previously registered await continuation.

* Fix nits
src/System.Private.CoreLib/shared/System/Threading/Tasks/Task.cs