public void TryPopTeset() { var mre = new ManualResetEventSlim(false); Task.Factory.StartNew(() => { Thread.Sleep(100); for (var i = 0; i < 100; i++) { Thread.Sleep(10); stack.Push(Rnd.Next(MaxNumber)); } mre.Set(); }); for (var i = 0; i < 100; i++) { Thread.Sleep(10); int item; if (stack.TryPop(out item)) { item.Should().Be.GreaterThanOrEqualTo(0).And.Be.LessThan(MaxNumber); } else { item.Should("item").Be(0); } } mre.Wait(); stack.Count.Should().Not.Be(0); }
T ReuseInstance(int pool, Func <T> onFirstInit) { T obj = null; ThreadSafeStack <T> localPool = ReturnValidPool(_recycledPools, pool); while (IsNull(obj) == true && localPool.count > 0) { localPool.TryPop(out obj); } if (IsNull(obj) == true) { obj = onFirstInit(); _objectsCreated++; } else { #if DEBUG && !PROFILE_SVELTO _alreadyRecycled.TryRemove(obj, out _); #endif _objectsReused++; } // ConcurrentStack<T> localUsedPool = ReturnValidPool(_usedPools, pool); // localUsedPool.Push(obj); return(obj); }