private static void OneThreadWithPool(int iterCount) { var pool = new ThirdPartyPool(1024, 0, 10); for (var i = 0; i < iterCount; i++) { using (var slot = pool.TakeSlot()) { } } }
private static void ManyThreadsWithPool(int iterCount, int taskCount) { var tasks = new Task[taskCount]; var pool = new ThirdPartyPool(1024, 0, 10); for (var t = 0; t < taskCount; t++) { tasks[t] = Task.Factory.StartNew( () => { for (var i = 0; i < iterCount; i++) { using (var slot = pool.TakeSlot()) { } } }); } Task.WaitAll(tasks); }