From ff315182efd0754428e6b9be2d4031b8e899f82a Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Thu, 25 Aug 2016 06:08:53 +0100 Subject: [PATCH] Remove idiv from ThreadPoolWorkQueue:Dequeue loop (#6781) --- src/mscorlib/src/System/Threading/ThreadPool.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/mscorlib/src/System/Threading/ThreadPool.cs b/src/mscorlib/src/System/Threading/ThreadPool.cs index 2ee7b76..09fe93c 100644 --- a/src/mscorlib/src/System/Threading/ThreadPool.cs +++ b/src/mscorlib/src/System/Threading/ThreadPool.cs @@ -685,11 +685,13 @@ namespace System.Threading if (null == callback) { WorkStealingQueue[] otherQueues = allThreadQueues.Current; - int i = tl.random.Next(otherQueues.Length); int c = otherQueues.Length; + int maxIndex = c - 1; + int i = tl.random.Next(c); while (c > 0) { - WorkStealingQueue otherQueue = Volatile.Read(ref otherQueues[i % otherQueues.Length]); + i = (i < maxIndex) ? i + 1 : 0; + WorkStealingQueue otherQueue = Volatile.Read(ref otherQueues[i]); if (otherQueue != null && otherQueue != wsq && otherQueue.TrySteal(out callback, ref missedSteal)) @@ -697,7 +699,6 @@ namespace System.Threading Contract.Assert(null != callback); break; } - i++; c--; } } -- 2.7.4