Repository: dotnet/runtime
File: src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPoolWorkQueue.cs (C#)

Code before:
        internal static bool Dispatch()
        {
            ThreadPoolWorkQueue workQueue = ThreadPool.s_workQueue;
            ThreadPoolWorkQueueThreadLocals tl = workQueue.GetOrCreateThreadLocals();

            if (s_assignableWorkItemQueueCount > 0)
            {
                workQueue.AssignWorkItemQueue(tl);
            }

            // Before dequeuing the first work item, acknowledge that the thread request has been satisfied
            workQueue._separated.queueProcessingStage = QueueProcessingStage.NotScheduled;

            // The state change must happen before sweeping queues for items.
            Interlocked.MemoryBarrier();

            object? workItem = DequeueWithPriorityAlternation(workQueue, tl, out bool missedSteal);
            if (workItem == null)
            {
                if (s_assignableWorkItemQueueCount > 0)
                {
                    workQueue.UnassignWorkItemQueue(tl);
                }

                // Missing a steal means there may be an item that we we were unable to get.
                // Effectively, we failed to fullfill our promise to check the queues after
                // clearing "Scheduled" flag.
                // We need to make sure someone will do another pass.
                if (missedSteal)
                {
                    workQueue.EnsureThreadRequested();
                }

                // Tell the VM we're returning normally, not because Hill Climbing asked us to return.
                return true;
            }

            // The workitems that are currently in the queues could have asked only for one worker.
            // We are going to process a workitem, which may take unknown time or even block.
            // In a worst case the current workitem will indirectly depend on progress of other
            // items and that would lead to a deadlock if noone else checks the queue.
            // We must ensure at least one more worker is coming if the queue is not empty.
            workQueue.EnsureThreadRequested();

            //
            // After this point, this method is no longer responsible for ensuring thread requests except for missed steals
            //

            // Has the desire for logging changed since the last time we entered?
            workQueue.RefreshLoggingEnabled();


Review comment (bug):
Typo: "fullfill" should be "fulfill"
```suggestion
                // Effectively, we failed to fulfill our promise to check the queues after
```

Code after:
                    workQueue.workItems.TryDequeue(out workItem);
                }
            }

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

            return workItem;
        }

        /// <summary>
        /// Dispatches work items to this thread.
        /// </summary>
        /// <returns>
        /// <c>true</c> if this thread did as much work as was available or its quantum expired.
        /// <c>false</c> if this thread stopped working early.
        /// </returns>
        internal static bool Dispatch()
        {
            ThreadPoolWorkQueue workQueue = ThreadPool.s_workQueue;
            ThreadPoolWorkQueueThreadLocals tl = workQueue.GetOrCreateThreadLocals();

            if (s_assignableWorkItemQueueCount > 0)
            {
                workQueue.AssignWorkItemQueue(tl);
            }

            // Before dequeuing the first work item, acknowledge that the thread request has been satisfied
            workQueue._separated._hasOutstandingThreadRequest = 0;

            // The state change must happen before sweeping queues for items.
            Interlocked.MemoryBarrier();

            object? workItem = DequeueWithPriorityAlternation(workQueue, tl, out bool missedSteal);
            if (workItem == null)
            {
                if (s_assignableWorkItemQueueCount > 0)
                {
                    workQueue.UnassignWorkItemQueue(tl);
                }

                // Missing a steal means there may be an item that we were unable to get.
                // Effectively, we failed to fulfill our promise to check the queues after
                // clearing "Scheduled" flag.
                // We need to make sure someone will do another pass.
                if (missedSteal)
                {
                    workQueue.EnsureThreadRequested();
                }

                // Tell the VM we're returning normally, not because Hill Climbing asked us to return.