Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Conversation

@stephentoub
Copy link
Member

  • Fixed some XML comments that incorrectly referred to Task instead of ValueTask
  • Renamed the internal Dequeue collection to be Deque to better conform to typical spelling
  • Reordered some items in the .csproj to be in alphabetical order
  • Fixed a small bug where if a non-default TaskScheduler was set and SynchronizationContext.Current was set to the base SynchronizationContext class (rather than being null), we would end up preferring the SynchronizationContext rather than using the TaskScheduler
  • Added tests to validate behavior for when both SynchronizationContext and TaskSchedulers were in play

cc: @tarekgh

Just to better conform to the typical spelling.
…t SyncContext

When {Unsafe}OnCompleted is called on an AsyncOperation in Channels, without ConfigureAwait(false), we look to see if there's a current non-default SynchronizationContext, and if there isn't, then a current non-default TaskScheduler.  That's stored for later when the operation is completed.  However, if as OnCompleted is being called the operation is completed, then rather than using this captured context or scheduler later, the continuation is immediately queued to the appropriate context.  When that happens, if the current SynchronizationContext was non-null but still the default (an instance of the base class), we're incorrectly ignoring whatever TaskScheduler may have been present, and end up queueing to the thread pool rather than to that scheduler.

The fix is just to ensure that, in that case, we don't pay attention to the default SynchronizationContext.  This does so and adds a test.
Validate that, when there's both a non-default SyncContext and a non-default TaskScheduler, we prefer the SyncContext.
@stephentoub stephentoub merged commit 207a50b into dotnet:master Oct 19, 2018
@stephentoub stephentoub deleted the channelsfixes branch October 19, 2018 22:18
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
* Fix a few XML comments

* Rename internal Dequeue<T> to Deque<T>

Just to better conform to the typical spelling.

* Fix includes ordering in Channels project file

* Fix continuation scheduling with non-default TaskScheduler and default SyncContext

When {Unsafe}OnCompleted is called on an AsyncOperation in Channels, without ConfigureAwait(false), we look to see if there's a current non-default SynchronizationContext, and if there isn't, then a current non-default TaskScheduler.  That's stored for later when the operation is completed.  However, if as OnCompleted is being called the operation is completed, then rather than using this captured context or scheduler later, the continuation is immediately queued to the appropriate context.  When that happens, if the current SynchronizationContext was non-null but still the default (an instance of the base class), we're incorrectly ignoring whatever TaskScheduler may have been present, and end up queueing to the thread pool rather than to that scheduler.

The fix is just to ensure that, in that case, we don't pay attention to the default SynchronizationContext.  This does so and adds a test.

* Add a test with both non-default SyncContext and TaskScheduler set

Validate that, when there's both a non-default SyncContext and a non-default TaskScheduler, we prefer the SyncContext.


Commit migrated from dotnet/corefx@207a50b
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.

2 participants