[corlib] Fix ObjectPool to not incorrectly assume it was succeeding when its trial...
authorJeremie Laval <jeremie.laval@gmail.com>
Wed, 25 Jul 2012 11:42:14 +0000 (12:42 +0100)
committerJeremie Laval <jeremie.laval@gmail.com>
Wed, 25 Jul 2012 11:42:14 +0000 (12:42 +0100)
Reported by Greg Young

mcs/class/corlib/System.Collections.Concurrent/ObjectPool.cs

index 6ef1658424360144254485b42943efcb76d0fb52..853953ba4922187573505f88c735ca5c1e1673f2 100644 (file)
@@ -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 ();