Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update awaiters to implement ICriticalNotifyCompletion #235

Closed
7 tasks done
sharwell opened this issue Apr 10, 2018 · 3 comments
Closed
7 tasks done

Update awaiters to implement ICriticalNotifyCompletion #235

sharwell opened this issue Apr 10, 2018 · 3 comments
Assignees

Comments

@sharwell
Copy link
Member

sharwell commented Apr 10, 2018

This interface allows callers that preserve their own execution contexts to avoid a call to ExecutionContext.Capture and ExecutionContext.Run during an await operation.

  • NoThrowTaskAwaiter
  • ConfiguredTaskYieldAwaiter
  • TaskSchedulerAwaiter
  • JoinableTaskFactory+MainThreadAwaiter
  • AsyncReaderWriterLock+Awaiter
  • AsyncReaderWriterResourceLock+ResourceAwaiter
  • InlineResumable
@AArnott AArnott self-assigned this Apr 10, 2018
@AArnott
Copy link
Member

AArnott commented Apr 19, 2018

I'm working on this now.

@AArnott
Copy link
Member

AArnott commented Apr 19, 2018

For the NoThrowTaskAwaiter, offering ICriticalNotifyCompletion effected this change to a continuation's callstack. Note the drop from two ExecutionContext.Run frames to just one.

-OnCompleted
+UnsafeOnCompleted
 >      Microsoft.VisualStudio.Threading.Tests.dll!Microsoft.VisualStudio.Threading.Tests.TplExtensionsTests.NoThrowAwaitable_Await_CapturesExecutionContext.AnonymousMethod__0() Line 290      C#
        [Resuming Async Method]
        mscorlib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner.InvokeMoveNext(object stateMachine)  Unknown
        mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)   Unknown
        mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)   Unknown
        mscorlib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner.Run()        Unknown
        mscorlib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.OutputAsyncCausalityEvents.AnonymousMethod__0()     Unknown
        mscorlib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.ContinuationWrapper.Invoke()        Unknown
        mscorlib.dll!System.Runtime.CompilerServices.TaskAwaiter.OutputWaitEtwEvents.AnonymousMethod__0()       Unknown
        mscorlib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.ContinuationWrapper.Invoke()        Unknown
-       mscorlib.dll!System.Threading.Tasks.AwaitTaskContinuation.InvokeAction(object state)    Unknown
-       mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)   Unknown
-       mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)   Unknown
-       mscorlib.dll!System.Threading.Tasks.AwaitTaskContinuation.RunCallback(System.Threading.ContextCallback callback, object state, ref System.Threading.Tasks.Task currentTask)     Unknown
-       mscorlib.dll!System.Threading.Tasks.AwaitTaskContinuation.Run(System.Threading.Tasks.Task task, bool canInlineContinuationTask) Unknown
+       mscorlib.dll!System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(System.Action action, bool allowInlining, ref System.Threading.Tasks.Task currentTask)    Unknown
        mscorlib.dll!System.Threading.Tasks.Task.FinishContinuations()  Unknown
        mscorlib.dll!System.Threading.Tasks.Task.FinishStageThree()     Unknown
        mscorlib.dll!System.Threading.Tasks.Task<System.__Canon>.TrySetResult(System.__Canon result)    Unknown
        mscorlib.dll!System.Threading.Tasks.TaskCompletionSource<System.__Canon>.TrySetResult(System.__Canon result)    Unknown
        mscorlib.dll!System.Threading.Tasks.TaskCompletionSource<System.__Canon>.SetResult(System.__Canon result)       Unknown
        Microsoft.VisualStudio.Threading.Tests.dll!Microsoft.VisualStudio.Threading.Tests.TplExtensionsTests.NoThrowAwaitable_Await_CapturesExecutionContext(bool captureContext) Line 294      C#
        [Resuming Async Method]
        mscorlib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner.InvokeMoveNext(object stateMachine)  Unknown
        mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)   Unknown
        mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)   Unknown
        mscorlib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner.Run()        Unknown
        mscorlib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.OutputAsyncCausalityEvents.AnonymousMethod__0()     Unknown
        mscorlib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.ContinuationWrapper.Invoke()        Unknown
        mscorlib.dll!System.Runtime.CompilerServices.TaskAwaiter.OutputWaitEtwEvents.AnonymousMethod__0()       Unknown
        mscorlib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.ContinuationWrapper.Invoke()        Unknown
        mscorlib.dll!System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation.GetActionLogDelegate.AnonymousMethod__0()       Unknown
        mscorlib.dll!System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation..cctor.AnonymousMethod__8_0(object state)       Unknown
        xunit.execution.desktop.dll!Xunit.Sdk.AsyncTestSyncContext.Post.AnonymousMethod__0()    Unknown
        xunit.execution.desktop.dll!Xunit.Sdk.XunitWorkerThread.QueueUserWorkItem.AnonymousMethod__4_0(object _)        Unknown
        mscorlib.dll!System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(object state)      Unknown
        mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)   Unknown
        mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)   Unknown
        mscorlib.dll!System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()  Unknown
        mscorlib.dll!System.Threading.ThreadPoolWorkQueue.Dispatch()    Unknown
        mscorlib.dll!System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()     Unknown

@AArnott
Copy link
Member

AArnott commented Apr 21, 2018

This issue can be closed when the two PRs linked above are merged.

@AArnott AArnott closed this as completed Apr 25, 2018
AArnott added a commit to AArnott/vs-threading that referenced this issue Jan 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants