From c1dac88f805fa4609ee31ca64fac6ee7a3debb06 Mon Sep 17 00:00:00 2001 From: ikopylov Date: Wed, 12 Oct 2016 17:28:45 +0300 Subject: [PATCH] Waiters notification by the value of releaseCount --- .../src/System/Threading/SemaphoreSlim.cs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/System.Private.CoreLib/src/System/Threading/SemaphoreSlim.cs b/src/System.Private.CoreLib/src/System/Threading/SemaphoreSlim.cs index cdcd55caac0..beae3e6f23f 100644 --- a/src/System.Private.CoreLib/src/System/Threading/SemaphoreSlim.cs +++ b/src/System.Private.CoreLib/src/System/Threading/SemaphoreSlim.cs @@ -778,14 +778,12 @@ public int Release(int releaseCount) // Signal to any synchronous waiters int waitCount = m_waitCount; - if (currentCount == 1 || waitCount == 1) + + int waitersToNotify = Math.Min(releaseCount, waitCount); + for (int i = 0; i < waitersToNotify; i++) { m_condition.SignalOne(); } - else if (waitCount > 1) - { - m_condition.SignalAll(); - } // Now signal to any asynchronous waiters, if there are any. While we've already // signaled the synchronous waiters, we still hold the lock, and thus