Add public IThreadPoolWorkItem (dotnet/coreclr#20387)
authorStephen Toub <stoub@microsoft.com>
Thu, 18 Oct 2018 10:01:49 +0000 (06:01 -0400)
committerGitHub <noreply@github.com>
Thu, 18 Oct 2018 10:01:49 +0000 (06:01 -0400)
commit1b440bd8966d87a8dd229f5b2acbb5193c10da8d
treeab33e98539cab0139c6ddfdb9c4717e2d59eb47e
parentb8ea37f88e1ec80bd4f349e6f62104175a028cb9
Add public IThreadPoolWorkItem (dotnet/coreclr#20387)

- Changes the internal IThreadPoolWorkItem to be public, removing the legacy ThreadAbortException from it (which was specific to Task, anyway).
- Removes the IThreadPoolWorkItem implementation from Task, so that devs can't write code like `ThreadPool.UnsafeQueueUserWorkItem(task);` or `((IThreadPoolWorkItem)task).Execute();`, both of which could end up doing a variety of bad things that could show up in a variety of ways, some discoverable, some less so.
- Adds an internal UnsafeQueueUserWorkItemInternal that takes object so that it can be passed either an IThreadPoolUserWorkItem or a Task,
- Changes the ThreadPool's queues to be in terms of object instead of IThreadPoolWorkItem
- Changes the dispatch loop to type check for IThreadPoolWorkItem or Task so that both remain supported.

Commit migrated from https://github.com/dotnet/coreclr/commit/0c7781113cec74ed69aa6a38f9a3e845f40c3680
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncMethodBuilder.cs
src/coreclr/src/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs
src/coreclr/src/System.Private.CoreLib/src/System/Threading/Tasks/TaskContinuation.cs
src/coreclr/src/System.Private.CoreLib/src/System/Threading/Tasks/ThreadPoolTaskScheduler.cs
src/coreclr/src/System.Private.CoreLib/src/System/Threading/ThreadPool.cs
src/coreclr/src/System.Private.CoreLib/src/System/Threading/Timer.cs
src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/YieldAwaitable.cs
src/libraries/System.Private.CoreLib/src/System/Threading/SemaphoreSlim.cs