public void run() { int n = 0; StressedPacket stressedPacketA = new StressedPacket(writer); StressedPacket stressedPacketB = new StressedPacket(writer); while (true) { // for (int i = 0; i < writer; i++) System.out.print (" "); // System.out.println (id + " " + n); stressedPacketA.n = n; Out.write(stressedPacketA); n++; // for (int i = 0; i < writer; i++) System.out.print (" "); // System.out.println (id + " " + n); stressedPacketB.n = n; Out.write(stressedPacketB); n++; } }
public void run() { const int seconds = 1000; const int initialWait = 5; //commented out as it doesn't add any value - Karol Pasierb //Console.WriteLine("\nWait (" + initialWait + // " seconds) for all the writers to get going ..."); //CSTimer tim = new CSTimer(); //long timeout = tim.read() + (initialWait * seconds); //tim.after(timeout); //Console.WriteLine("OK - that should be long enough ...\n"); int[][] n = new int[c.Length][]; for (int i = 0; i < n.Length; i++) { n[i] = new int[nWritersPerChannel]; } //commented out for performance testing - Karol Pasierb //for (int channel = 0; channel < c.Length; channel++) //{ // for (int i = 0; i < nWritersPerChannel; i++) // { // StressedPacket stressedPacket = (StressedPacket)c[channel].read(); // n[channel][stressedPacket.writer] = stressedPacket.n; // for (int chan = 0; chan < channel; chan++) Console.Write(" "); // Console.WriteLine("channel " + channel + // " writer " + stressedPacket.writer + // " read " + stressedPacket.n); // } //} Alternative alt = new Alternative(c); int counter = 0, tock = 0; long t0 = 0, t1 = 0, microseconds = 0; while (true) { if (counter == 0) { /*t1 = CSPTimeMillis.CurrentTimeMillis(); * microseconds = (t1 - t0); * Console.WriteLine("Reading time for tock " + tock + ": " + microseconds);*/ Console.Write("Tock " + tock + " : "); int total = 0; for (int channel = 0; channel < n.Length; channel++) { Console.Write(n[channel][tock % nWritersPerChannel] + " "); for (int i = 0; i < nWritersPerChannel; i++) { total += n[channel][i]; } } Console.WriteLine(": " + total); tock++; counter = 10000; // t0 = CSPTimeMillis.CurrentTimeMillis(); //Debug.WriteLine("Read time at counter 10000"); } counter--; t0 = CSTimer.CurrentTimeMillis(); int channelFairSelect = alt.fairSelect(); StressedPacket stressedPacket = (StressedPacket)c[channelFairSelect].read(); n[channelFairSelect][stressedPacket.writer] = stressedPacket.n; t1 = CSTimer.CurrentTimeMillis(); microseconds = (t1 - t0) * 1000; if (microseconds > 0) { Debug.WriteLine("Reading time for tock " + tock + ": " + microseconds); } // for (int chan = 0; chan < channel; chan++) System.out.print (" "); // Console.WriteLine ("channel " + channel + // " writer " + stressedPacket.writer + // " read " + stressedPacket.n); } }