public static void ParallelAdder(IProducerConsumerCollection <int> collection, int numThread) { int startIndex = -10; ParallelTestHelper.ParallelStressTest(collection, delegate(IProducerConsumerCollection <int> c) { int start = Interlocked.Add(ref startIndex, 10); for (int i = start; i < start + 10; i++) { c.TryAdd(i); } }, numThread); }
public static void ParallelRemover(IProducerConsumerCollection <int> collection, int numThread, int times) { int t = -1; ParallelTestHelper.ParallelStressTest(collection, delegate(IProducerConsumerCollection <int> c) { int num = Interlocked.Increment(ref t); int value; if (num < times) { c.TryTake(out value); } }, numThread); }