static long ClassicTestRun(int readThreads, int writeThreads) { Console.Write($" * ClassicTestRun({readThreads}, {writeThreads}): CRTHD"); counters = new long[writeThreads]; syncs = new object[writeThreads]; int threadsPerWriter = readThreads / writeThreads; threads = threadsPerWriter * writeThreads; for (int writer = 0; writer < writeThreads; writer++) { syncs[writer] = new object(); List <ClassicPipeSimulation> clients = new List <ClassicPipeSimulation>(); Thread thd = new Thread(new ParameterizedThreadStart(writeClassic)); thd.Start(new object?[] { clients, writer }); for (int client = 0; client < threadsPerWriter; client++) { ClassicPipeSimulation pipe = new ClassicPipeSimulation(); clients.Add(pipe); thd = new Thread(new ParameterizedThreadStart(readClassic)); thd.Start(new object?[] { pipe, writer }); } } Console.Write(", WARMUP"); Thread.Sleep(1000); runReaders = true; runWriters = true; mre.Set(); Thread.Sleep(30000); Console.Write(", START"); for (int writer = 0; writer < writeThreads; writer++) { lock (syncs[writer]) counters[writer] = 0; } Stopwatch sw = Stopwatch.StartNew(); Thread.Sleep(60000); long result = 0; for (int writer = 0; writer < writeThreads; writer++) { result += counters[writer]; } sw.Stop(); Console.Write(", CLDN"); mre.Reset(); runReaders = false; while (true) { Thread.Sleep(100); lock (threadSync) if (threads == 0) { break; } } runWriters = false; Thread.Sleep(1000); Console.WriteLine($": {(long)(result / sw.Elapsed.TotalMinutes + 0.5)}."); return((long)(result / sw.Elapsed.TotalMinutes + 0.5)); }
static void readClassic(object?parameter) { mre.WaitOne(); ClassicPipeSimulation client = (ClassicPipeSimulation)((object[])parameter !)[0];