This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Use clean contexts for IO Thread callbacks#21327
Closed
benaadams wants to merge 1 commit intodotnet:masterfrom
Closed
Use clean contexts for IO Thread callbacks#21327benaadams wants to merge 1 commit intodotnet:masterfrom
benaadams wants to merge 1 commit intodotnet:masterfrom
Conversation
Member
Author
|
Starting on the default context here and for the ThreadPool with // Start on clean ExecutionContext and SynchronizationContext
currentThread.ExecutionContext = null;
currentThread.SynchronizationContext = null;Is probably overly pessimistic; but not sure if the threads get used elsewhere as there are a number of callback types into the runtime from unmanaged code. |
Member
Author
|
Note: this wouldn't resolve what I was trying to address in #21320 because SocketEventArgs captures its own contexts then the run here is flow supressed so it still goes via the full However, already issue for the SocketEventArgs capture dotnet/corefx#32582 |
24db90d to
7fdb446
Compare
Member
Author
|
Broke something in the rebase; though I'm not strongly attached to this change |
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.
For
PerformIOCompletionCallbackskips the use of_IOCompletionCallbackwhenExecutionContextflow is suppressed or Default.However, if any changes were made by the callback to the
ExecutionContext; they would not be undone, nor fire change notifications withThreadContextChanged == true; additionally those changes would then flow into the next flow suppressed callback or Default context callback.This change starts the
PerformIOCompletionCallbackthread on the Default (null) context; then after each loop iteration it also undoes any changes made in the callback to the context; including firingThreadContextChanged == truenotifications; so they no longer can flow into the next iteration or activation ofPerformIOCompletionCallback.Additionally it includes the optimization from #21320 of only looking up the
Thread.CurrentThreadonce per loop; and using the fast-path ExecutionContext.Run that the ThreadPool uses (renamed in this fromRunForThreadPoolUnsafetoRunForThreadLoopUnsafe)./cc @stephentoub @jkotas @kouvel