Skip to content
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
stephentoub:unsaferegister
May 16, 2019
Merged

Use CancellationToken.UnsafeRegister in a few more places#37551
stephentoub merged 1 commit intodotnet:masterfrom
stephentoub:unsaferegister

Conversation

@stephentoub
Copy link
Copy Markdown
Member

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.

@stephentoub stephentoub force-pushed the unsaferegister branch 2 times, most recently from 41fd7ab to 4eb3c9f Compare May 9, 2019 18:00
@stephentoub
Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 2 pipeline(s), but failed to run 2 pipeline(s).

@ViktorHofer ViktorHofer closed this May 9, 2019
@ViktorHofer ViktorHofer reopened this May 9, 2019
@ViktorHofer
Copy link
Copy Markdown
Member

@chcosta any idea why this is frequently happening?

/eng/pipelines/corefx-base.yml: Could not find /eng/common/templates/job/job.yml in repository self hosted on https://api.github.com using commit 2bc9594. GitHub reported the error, "Not Found"

PRs are failing because of this.

@chcosta
Copy link
Copy Markdown
Member

chcosta commented May 9, 2019

There's a long mail thread about this with no satisfactory resolution. I'll forward it to you.

@stephentoub
Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 4 pipeline(s).

@stephentoub stephentoub reopened this May 14, 2019
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.
@stephentoub stephentoub merged commit b1a1bfa into dotnet:master May 16, 2019
@stephentoub stephentoub deleted the unsaferegister branch May 16, 2019 18:08
@karelz karelz added this to the 3.0 milestone May 22, 2019
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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants