public void run() { CSTimer timer = new CSTimer(); Random rnd = new Random(); int randomTimeout = rnd.Next(1, 10) * n * 500; timeout = timer.read() + randomTimeout; Debug.WriteLine(n + "Process timeout " + randomTimeout); Object x = input.read(); Console.WriteLine(n + "Read value" + x); while (true) { x = input.read(); Console.WriteLine(n + "Read value" + x); //output.write(x); long currentTime = timer.read(); if (timeout <= currentTime) //if timeout should occur now { timeout = timer.read() + rnd.Next(1, 10) * 500; Debug.WriteLine(n + "Process timout ppassed " + randomTimeout); output.write(n + "For Input guard" + x + "0000000"); timer.after(timeout); output.write(n + "Finished"); timeout = timer.read() + rnd.Next(1, 10) * n * 500; } } }
public void run() { Guard[] guards = new Guard[In.Length + 1]; Array.Copy(In, 0, guards, 0, In.Length); CSTimer tim = new CSTimer(); int timerIndex = In.Length; guards[timerIndex] = tim; Alternative alt = new Alternative(guards); Boolean running = true; tim.setAlarm(tim.read() + timeout); while (running) { int index = alt.fairSelect(); if (index == timerIndex) { running = false; } else { Out.write(In[index].read()); } } Console.WriteLine("Goodbye from FairPlexTime ..."); //System.exit(0); }
public void run() { CSTimer tim = new CSTimer(); CSTimer reset = new CSTimer(); Guard[] guards = { reset, tim, In as Guard }; // prioritised order const int RESET = 0; // index into guards const int TIM = 1; // index into guards const int IN = 2; // index into guards Alternative alt = new Alternative(guards); int x = 0; long timeout = tim.read() + 3000; tim.setAlarm(timeout); long resetting = reset.read() + 5000; reset.setAlarm(resetting); while (true) { switch (alt.priSelect()) { case RESET: resetting = reset.read() + 5000; reset.setAlarm(resetting); Out.write("Numbers reset"); break; // fall through case TIM: timeout = tim.read(); Out.write(x * 10); timeout += 3000; tim.setAlarm(timeout); break; case IN: x = (int)In.read(); Out.write(x); break; } } }
/** * The main body of this process. */ public void run() { CSTimer tim = new CSTimer(); Guard[] guards = { reset, tim, In }; // prioritised order const int RESET = 0; // index into guards const int TIM = 1; // index into guards const int IN = 2; // index into guards Alternative alt = new Alternative(guards); Object x = 1; // holding object long interval = initialInterval; long timeout = tim.read() + interval; tim.setAlarm(timeout); while (true) { switch (alt.priSelect()) { case RESET: //interval = ((long)reset.read()).longValue(); interval = (long)reset.read(); timeout = tim.read(); // fall through Out.write(x); timeout += interval; tim.setAlarm(timeout); break; case TIM: Out.write(x); timeout += interval; tim.setAlarm(timeout); break; case IN: x = In.read(); break; } } }
public void run() { CSTimer timer = new CSTimer(); long timeout = timer.read(); // read the (absolute) time once only while (true) { N++; Out.write(N); timeout += interval; // set the next (absolute) timeOut timer.after(timeout); // wait until that (absolute) timeOut } }
public void run() { CSTimer timer = new CSTimer(); while (true) { //Console.WriteLine("Inside GPrint timer"); if (delay != 0) { timer.after(timer.read() + delay); Console.WriteLine(heading.Split(' ')[0] + " \t" + inChannel.read()); } } }
public void run() { CSTimer tim = new CSTimer(); int CHICKENS = 4; toConsole.write("Starting ... \n"); while (true) { toConsole.write("Cooking ... \n"); // cook 4 chickens; tim.after(tim.read() + 2000); // this takes 2 seconds to cook; toConsole.write(CHICKENS + "chickens ready ... \n"); supply.write(CHICKENS); toConsole.write("Taking chickens to Canteen ... \n"); supply.write(0); } }
public void run() { //initialize internal arrays of 2-dimensional array int[][] n = new int[c.Length][]; for (int i = 0; i < n.Length; i++) { n[i] = new int[nWritersPerChannel]; } //setup variables const int initialWait = 3000; int iterations = nMessages * nChannels * nWritersPerChannel; long t0 = 0, t1 = 0, microseconds = 0; Alternative alt = new Alternative(c); CSTimer timer = new CSTimer(); int channelFairSelect = 0; StressedPacket stressedPacket; var csv = new StringBuilder(); //set the timer to wait for 5 seconds to make sure that all the readers are idle in writing state Console.WriteLine("Waiting 3 seconds..."); timer.after(initialWait + timer.read()); Console.WriteLine("Waiting is over. Measuring time"); //perform read and measure the time t0 = CSTimer.CurrentTimeMillis(); for (int i = 0; i < iterations; i++) { channelFairSelect = alt.fairSelect(); stressedPacket = (StressedPacket)c[channelFairSelect].read(); n[channelFairSelect][stressedPacket.writer] = stressedPacket.n; } t1 = CSTimer.CurrentTimeMillis(); microseconds = (t1 - t0) * 1000; if (microseconds > 0) { Console.WriteLine("Reading time for " + iterations + " iterations: " + microseconds); var newLine = string.Format("{0},{1},{2},{3},{4}", nChannels, nWritersPerChannel, nMessages, iterations, microseconds); csv.AppendLine(newLine); File.AppendAllText(@"d:\\NetworkedstressedAlt_Test" + nChannels + "x" + nWritersPerChannel + ".csv", csv.ToString()); } }
public void run() { CSTimer timer = new CSTimer(); int n_chickens; Console.WriteLine(" Chef : starting ... "); while (true) { // cook 4 chickens Console.WriteLine(" Chef : cooking ... "); timer.after(timer.read() + 2000); // this takes 3 seconds to cook n_chickens = 4; Console.WriteLine(" Chef : " + n_chickens + " chickens, ready-to-go ... "); supply.write(n_chickens); // supply the chickens supply.write(0); // wait till they're set down } }
public void run() { int currentFactor = 0; var timer = new CSTimer(); var timeout = timer.read(); while (true) { timeout = timeout + testInterval; timer.after(timeout); suspend.write(0); currentFactor = (int)factor.read(); currentFactor = currentFactor + addition; timer.sleep(computeInterval); injector.write(currentFactor); } }
public void run() { long halfSecond = 500; long second = 1000; CSTimer tim = new CSTimer(); long timeout = tim.read(); while (true) { timeout += 5000; tim.after(timeout); Console.WriteLine(" <== now every second"); reset.Out().write(second); timeout += 5000; tim.after(timeout); Console.WriteLine(" <== now every half second"); reset.Out().write(halfSecond); } }
public void run() { Guard[] canteenGuards = { supply as Guard, service as Guard }; Boolean[] precondition = { true, false }; var canteenAlt = new Alternative(canteenGuards); const int SUPPLY = 0; const int SERVICE = 1; CSTimer tim = new CSTimer(); int chickens = 0; toConsole.write("Canteen : starting ... \n"); while (true) { precondition[SERVICE] = (chickens > 0); if (chickens == 0) { toConsole.write("Waiting for chickens ...\n"); } switch (canteenAlt.fairSelect(precondition)) { case SUPPLY: int value = (int)(long)supply.read(); toConsole.write("Chickens on the way ...\n"); tim.after(tim.read() + 3000); chickens = chickens + value; toConsole.write(chickens + " chickens now available ...\n"); supply.read(); break; case SERVICE: int id = (int)(long)service.read(); chickens = chickens - 1; toConsole.write("chicken ready for Philosoper " + id + " ... " + chickens + " chickens left \n"); deliver.write(1); break; } } }
public void run() { CSTimer tim = new CSTimer(); Console.WriteLine(" Philosopher " + id + " : starting ... "); while (true) { // everyone, bar Philosopher 0, has a little think if (id > 0) { tim.after(tim.read() + 3000); // thinking } // want chicken Console.WriteLine(" Philosopher " + id + " : gotta eat ... "); service.write(0); deliver.read(); Console.WriteLine(" Philosopher " + id + " : mmm ... that's good ... "); } }
public void run() { Alternative alt = new Alternative(new Guard[] { supply, service }); Boolean[] precondition = { true, false }; const int SUPPLY = 0; const int SERVICE = 1; CSTimer timer = new CSTimer(); int nChickens = 0; Console.WriteLine(" Canteen : starting ... "); while (true) { precondition[SERVICE] = (nChickens > 0); switch (alt.fairSelect(precondition)) { case SUPPLY: int value = (int)supply.read(); // new batch of chickens from the Chef Console.WriteLine(" Canteen : ouch ... make room ... this dish is very hot ... "); timer.after(timer.read() + 3000); // this takes 3 seconds to put down nChickens += value; Console.WriteLine(" Canteen : more chickens ... " + nChickens + " now available ... "); supply.read(); // let the Chef get back to cooking break; case SERVICE: service.read(); // Philosopher wants a chicken Console.WriteLine(" Canteen : one chicken coming down ... " + (nChickens - 1) + " left ... "); deliver.write(1); // serve one chicken nChickens--; break; } } }
public void run() { int innerCycleTime = n * start; CSTimer tim = new CSTimer(); long timeout = tim.read(); while (true) { int interval = start; while (interval >= stop) { int innerCycles = innerCycleTime / interval; for (int i = 0; i < innerCycles; i++) { Out.write(interval); timeout += (long)interval; tim.after(timeout); } interval /= 2; } } }
public void run() { int SECOND = 1000; int DOUBLE_INTERVAL = 5 * SECOND; const int NORMAL_SUSPEND = 0; const int NORMAL_TIMER = 1; const int NORMAL_IN = 2; const int SUSPENDED_INJECT = 0; const int SUSPENDED_IN = 1; var timer = new CSTimer(); var normalAlt = new Alternative(new Guard[] { suspend as Guard, timer as Guard, inChannel as Guard }); var suspendedAlt = new Alternative(new Guard[] { injector as Guard, inChannel as Guard }); var timeout = timer.read() + DOUBLE_INTERVAL; timer.setAlarm(timeout); int inValue; ScaledData result; while (true) { switch (normalAlt.priSelect()) { case NORMAL_SUSPEND: suspend.read(); // its a signal, no data content; factor.write(scaling); //reply with current value of scaling; bool suspended = true; Console.WriteLine("\n\tSuspended"); while (suspended) { switch (suspendedAlt.priSelect()) { case SUSPENDED_INJECT: scaling = (int)injector.read(); //this is the resume signal as well; Console.WriteLine("\n\tInjected scaling is " + scaling); suspended = false; timeout = timer.read() + DOUBLE_INTERVAL; timer.setAlarm(timeout); break; case SUSPENDED_IN: inValue = (int)inChannel.read(); result = new ScaledData(); result.Original = inValue; result.Scaled = inValue; outChannel.write(result.ToString()); break; } // end-switch } //end-while break; case NORMAL_TIMER: timeout = timer.read() + DOUBLE_INTERVAL; timer.setAlarm(timeout); scaling = scaling * multiplier; Console.WriteLine("\n\tNormal Timer: new scaling is " + scaling); break; case NORMAL_IN: inValue = (int)inChannel.read(); result = new ScaledData(); result.Original = inValue; result.Scaled = inValue * scaling; outChannel.write(result.ToString()); break; } //end-switch } }