Skip to content

Make TimeProvider Delay Continuations Synchronously - #90489

Merged
tarekgh merged 8 commits into
dotnet:mainfrom
tarekgh:MakeTimeProviderDelayContinuationsSynchronously
Aug 14, 2023
Merged

Make TimeProvider Delay Continuations Synchronously#90489
tarekgh merged 8 commits into
dotnet:mainfrom
tarekgh:MakeTimeProviderDelayContinuationsSynchronously

Conversation

@tarekgh

@tarekgh tarekgh commented Aug 13, 2023

Copy link
Copy Markdown
Member

Fixes #85326

The TimeProvider in .NET 8.0 offers Task Delay functionality, and this functionality is also accessible in earlier versions using the System.Bcl.TimeProvider library. When invoked within the .NET 8.0 runtime, it generates a Task like using DelayPromise, configured with a state flags value of 0x07000400. This setting signifies that the Task's continuation will be executed synchronously. Once the Delay duration elapses, the RunContinuations function is triggered. Within this process, a check is performed (at this point), leading to the synchronous execution of the task continuation due to the absence of the TaskCreationOptions.RunContinuationsAsynchronously flag.

In cases where we operate on earlier runtime versions, we explicitly enable the TaskCreationOptions.RunContinuationsAsynchronously flag, which modifies the behavior of task continuations compared to .NET 8.0. To ensure consistent behavior with .NET 8.0, the recommended solution is to refrain from setting the TaskCreationOptions.RunContinuationsAsynchronously flag when executing on earlier runtime versions.

@ghost ghost added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Aug 13, 2023
@ghost ghost assigned tarekgh Aug 13, 2023
@tarekgh
tarekgh requested a review from stephentoub August 13, 2023 17:11
Comment thread src/libraries/Common/tests/System/TimeProviderTests.cs Outdated
Comment thread src/libraries/Common/tests/System/TimeProviderTests.cs
tarekgh and others added 2 commits August 14, 2023 08:35
…Tasks/TimeProviderTaskExtensions.cs

Co-authored-by: Stephen Toub <stoub@microsoft.com>
Co-authored-by: Stephen Toub <stoub@microsoft.com>
@ghost

ghost commented Aug 14, 2023

Copy link
Copy Markdown

Tagging subscribers to this area: @dotnet/area-system-datetime
See info in area-owners.md if you want to be subscribed.

Issue Details

Fixes #85326

The TimeProvider in .NET 8.0 offers Task Delay functionality, and this functionality is also accessible in earlier versions using the System.Bcl.TimeProvider library. When invoked within the .NET 8.0 runtime, it generates a Task like using DelayPromise, configured with a state flags value of 0x07000400. This setting signifies that the Task's continuation will be executed synchronously. Once the Delay duration elapses, the RunContinuations function is triggered. Within this process, a check is performed (at this point), leading to the synchronous execution of the task continuation due to the absence of the TaskCreationOptions.RunContinuationsAsynchronously flag.

In cases where we operate on earlier runtime versions, we explicitly enable the TaskCreationOptions.RunContinuationsAsynchronously flag, which modifies the behavior of task continuations compared to .NET 8.0. To ensure consistent behavior with .NET 8.0, the recommended solution is to refrain from setting the TaskCreationOptions.RunContinuationsAsynchronously flag when executing on earlier runtime versions.

Author: tarekgh
Assignees: tarekgh
Labels:

area-System.DateTime, needs-area-label

Milestone: -

@tarekgh tarekgh removed the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Aug 14, 2023
@tarekgh tarekgh added this to the 8.0.0 milestone Aug 14, 2023
Comment thread src/libraries/Common/tests/System/TimeProviderTests.cs
Comment thread src/libraries/Common/tests/System/TimeProviderTests.cs Outdated
Comment thread src/libraries/Common/tests/System/TimeProviderTests.cs Outdated
Co-authored-by: Stephen Toub <stoub@microsoft.com>
Comment thread src/libraries/Common/tests/System/TimeProviderTests.cs Outdated
tarekgh and others added 2 commits August 14, 2023 10:39
Co-authored-by: Stephen Toub <stoub@microsoft.com>
Co-authored-by: Stephen Toub <stoub@microsoft.com>
@tarekgh
tarekgh merged commit e9c4d48 into dotnet:main Aug 14, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Sep 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Should TimeProviderTaskExtensions run continuations synchronously?

2 participants