Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,6 @@ public int Count
(Environment.ProcessorCount + (ProcessorsPerAssignableWorkItemQueue - 1)) / ProcessorsPerAssignableWorkItemQueue;

private bool _loggingEnabled;
private bool _dispatchNormalPriorityWorkFirst;

// SOS's ThreadPool command depends on the following names
internal readonly WorkQueue workItems = new WorkQueue();
Expand Down Expand Up @@ -840,32 +839,6 @@ public long GlobalCount
// Dispatch (if YieldFromDispatchLoop is true), or performing periodic activities
public const uint DispatchQuantumMs = 30;

private static object? DequeueWithPriorityAlternation(ThreadPoolWorkQueue workQueue, ThreadPoolWorkQueueThreadLocals tl, out bool missedSteal)
{
object? workItem = null;

// Alternate between checking for high-prioriy and normal-priority work first, that way both sets of work
// items get a chance to run in situations where worker threads are starved and work items that run also
// take over the thread, sustaining starvation. For example, when worker threads are continually starved,
// high-priority work items may always be queued and normal-priority work items may not get a chance to run.
bool dispatchNormalPriorityWorkFirst = workQueue._dispatchNormalPriorityWorkFirst;
if (dispatchNormalPriorityWorkFirst && !tl.workStealingQueue.CanSteal)
{
workQueue._dispatchNormalPriorityWorkFirst = !dispatchNormalPriorityWorkFirst;
WorkQueue queue =
s_assignableWorkItemQueueCount > 0 ? tl.assignedGlobalWorkItemQueue : workQueue.workItems;
if (!queue.TryDequeue(out workItem) && s_assignableWorkItemQueueCount > 0)
{
workQueue.workItems.TryDequeue(out workItem);
}
}

missedSteal = false;
workItem ??= workQueue.Dequeue(tl, ref missedSteal);

return workItem;
}

/// <summary>
/// Dispatches work items to this thread.
/// </summary>
Expand All @@ -877,7 +850,8 @@ internal static bool Dispatch()
{
ThreadPoolWorkQueue workQueue = ThreadPool.s_workQueue;
ThreadPoolWorkQueueThreadLocals tl = workQueue.GetOrCreateThreadLocals();
object? workItem = DequeueWithPriorityAlternation(workQueue, tl, out bool missedSteal);
bool missedSteal = false;
object? workItem = workQueue.Dequeue(tl, ref missedSteal);
if (workItem == null)
{
// Missing a steal means there may be an item that we were unable to get.
Expand Down