public static Worker Run(AsyncSemaphoreSlim semaphore, int t) { Worker ret = new Worker(); ret.m_name = "Worker:" + t.ToString(); ret.m_semaphore = semaphore; var thread = new Thread(ret.DoWork); thread.IsBackground = true; thread.Start(); return(ret); }
private void Stress(IAsyncSemaphoreSlim sema, int numWorkers, int numRounds) { Console.WriteLine("Stress test for {0}", sema.GetType().FullName); var sw = Stopwatch.StartNew(); Worker.s_rounds = numRounds; Worker.s_totalCount = Worker.s_rounds * numWorkers; Worker.s_done = new ManualResetEvent(false); var semaphore = new AsyncSemaphoreSlim(10, 10); for (int i = 0; i < numWorkers; i++) { Worker.Run(semaphore, i); } Worker.s_done.WaitOne(); Console.WriteLine("...Done in {0} msec", sw.ElapsedMilliseconds); }