From 37c812036b161b7636698ed5256c6e3b2770e063 Mon Sep 17 00:00:00 2001 From: Jeremie Laval Date: Wed, 25 Jul 2012 12:42:14 +0100 Subject: [PATCH] [corlib] Fix ObjectPool to not incorrectly assume it was succeeding when its trial period ran out Reported by Greg Young --- .../corlib/System.Collections.Concurrent/ObjectPool.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mcs/class/corlib/System.Collections.Concurrent/ObjectPool.cs b/mcs/class/corlib/System.Collections.Concurrent/ObjectPool.cs index 6ef16584243..853953ba492 100644 --- a/mcs/class/corlib/System.Collections.Concurrent/ObjectPool.cs +++ b/mcs/class/corlib/System.Collections.Concurrent/ObjectPool.cs @@ -95,11 +95,11 @@ namespace System.Collections.Concurrent do { i = addIndex; } while ((i & bit) > 0); - // If no more room just forget about the object altogether - if (i - removeIndex >= capacity - 1) + // If no more room or too busy just forget about the object altogether + if (i - removeIndex >= capacity - 1 || tries == 0) return; // We update addIndex and notify that we are going to set buffer correctly - } while (Interlocked.CompareExchange (ref addIndex, i + 1 + bit, i) != i && --tries > 0); + } while (Interlocked.CompareExchange (ref addIndex, i + 1 + bit, i) != i && --tries > -1); buffer[i % capacity] = obj; Thread.MemoryBarrier (); -- 2.25.1