This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Use CancellationToken.UnsafeRegister in a few more places#37551
Merged
stephentoub merged 1 commit intodotnet:masterfrom May 16, 2019
Merged
Use CancellationToken.UnsafeRegister in a few more places#37551stephentoub merged 1 commit intodotnet:masterfrom
stephentoub merged 1 commit intodotnet:masterfrom
Conversation
41fd7ab to
4eb3c9f
Compare
Member
Author
|
/azp run |
|
Azure Pipelines successfully started running 2 pipeline(s), but failed to run 2 pipeline(s). |
Member
|
@chcosta any idea why this is frequently happening?
PRs are failing because of this. |
Member
|
There's a long mail thread about this with no satisfactory resolution. I'll forward it to you. |
Member
Author
|
/azp run |
|
Azure Pipelines successfully started running 4 pipeline(s). |
bartonjs
approved these changes
May 15, 2019
4eb3c9f to
cdac950
Compare
CancellationToken.Register captures the current ExecutionContext and uses it to invoke the callback if/when it's invoked. That's generally desirable and is the right default, but in cases where we know for certain the callback doesn't care about EC (e.g. we're not invoking any 3rd-party code), we can use UnsafeRegister instead (newly added in 3.0), which skips capturing the ExecutionContext, as if Capture returned null. This helps few a couple of small costs: - Avoids thread local lookups to capture the current EC. - Avoids additional delegate invocations and thread local gets/sets to invoke the callback with the captured EC. - Avoids holding on to the EC in case it's needed, which can potentially keep alive an unbounded amount of state due to AsyncLocals.
cdac950 to
53b0fe9
Compare
picenka21
pushed a commit
to picenka21/runtime
that referenced
this pull request
Feb 18, 2022
…efx#37551) CancellationToken.Register captures the current ExecutionContext and uses it to invoke the callback if/when it's invoked. That's generally desirable and is the right default, but in cases where we know for certain the callback doesn't care about EC (e.g. we're not invoking any 3rd-party code), we can use UnsafeRegister instead (newly added in 3.0), which skips capturing the ExecutionContext, as if Capture returned null. This helps few a couple of small costs: - Avoids thread local lookups to capture the current EC. - Avoids additional delegate invocations and thread local gets/sets to invoke the callback with the captured EC. - Avoids holding on to the EC in case it's needed, which can potentially keep alive an unbounded amount of state due to AsyncLocals. Commit migrated from dotnet/corefx@b1a1bfa
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CancellationToken.Register captures the current ExecutionContext and uses it to invoke the callback if/when it's invoked. That's generally desirable and is the right default, but in cases where we know for certain the callback doesn't care about EC (e.g. we're not invoking any 3rd-party code), we can use UnsafeRegister instead (newly added in 3.0), which skips capturing the ExecutionContext, as if Capture returned null. This helps few a couple of small costs: