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() { long x = -1; int warm_up = 1000; Console.WriteLine("warming up ... "); for (int i = 0; i < warm_up; i++) { x = (long)In.read(); } Console.WriteLine("last number received = " + x); Console.WriteLine("1000 cycles completed ... timing now starting ..."); var csv = new StringBuilder(); int repeatTimes = 1000; while (repeatTimes > 0) { long t0 = CSTimer.CurrentTimeMillis(); for (int i = 0; i < nLoops; i++) { x = (long)In.read(); } long t1 = CSTimer.CurrentTimeMillis(); Console.WriteLine("last number received = " + x); long microseconds = (t1 - t0) * 1000; long iterations = (microseconds / ((long)nLoops)); string first = " microseconds / iteration"; Console.WriteLine(iterations + first); long communication = (microseconds / ((long)(4 * nLoops))); string second = " microseconds / communication"; Console.WriteLine(communication + second); long contextSwitch = (microseconds / ((long)(8 * nLoops))); string third = " microseconds / context switch"; Console.WriteLine(contextSwitch + third); var newLine = string.Format("{0},{1},{2},{3},{4},{5}", iterations, first, communication, second, contextSwitch, third); csv.AppendLine(newLine); repeatTimes--; } File.WriteAllText(@"d:\\networkedCommsTimeTEST.csv", csv.ToString()); Console.WriteLine("Finished"); }
public void run() { string input = inChannel.read().ToString(); Console.WriteLine(input); outChannel.write(input); }
public void run() { CSTimer tim = new CSTimer(); toConsole.write("Starting ... \n"); while (true) { toConsole.write("Thinking ... \n"); if (id > 0) { tim.sleep(3000); } else { // Philosopher 0, has a 0.1 second think tim.sleep(100); } toConsole.write("Need a chicken ...\n"); service.write(id); int gotOne = (int)deliver.read(); if (gotOne > 0) { toConsole.write("Eating ... \n"); tim.sleep(2000); toConsole.write("Brrrp ... \n"); } else { toConsole.write(" Oh dear No chickens left \n"); } } }
/** * The main body of this process. */ public void run() { while (true) { Out.write(In.read()); } }
/** * Receives some data from a client once a connection * has been established. This will block until the client * calls <code>request(Object)</code> but by establishing * a connection. * * @return the <code>Object</code> sent by the client. */ public Object request() //throws IllegalStateException { if (currentServerState == SERVER_STATE_RECEIVED) { throw new InvalidOperationException("Cannot call request() twice on ConnectionServer without replying to the client first."); } ConnectionClientMessage msg = (ConnectionClientMessage)currentInputChannel.read(); if (currentServerState == SERVER_STATE_CLOSED) { if (msg is ConnectionClientOpenMessage) { //channel to use to reply to client toClient = ((ConnectionClientOpenMessage)msg).replyChannel; setAltingChannel(furtherRequestIn); currentInputChannel = furtherRequestIn; //create a new msg for connection established //don't know if client implementation will have finished with //message after connection closed this.msg = new ConnectionServerMessage(); } else { throw new InvalidOperationException("Invalid message received from client"); } } currentServerState = SERVER_STATE_RECEIVED; return(msg.data); }
public void run() { while (true) { Console.WriteLine(frameLabel + "\t" + toConsole.read()); } }
public void run() { int input = Int32.Parse(inChannel.read().ToString()); Console.WriteLine(input + " - It is an Int"); outChannel.write(input); }
/** * The main body of this process. */ public void run() { while (true) { int i = Int32.Parse(In.read().ToString()); Out.write(i + 1); } }
public void reply(Object data, Boolean close) { connectionServerToUse.reply(data, close); if (connectionServerToUse.getServerState() == AltingConnectionServerImpl.SERVER_STATE_CLOSED) { synchIn.read(); } }
public void run() { Skip flush = new Skip(); Alternative vAlt = new Alternative(new Guard[] { needToConsult as Guard, consultationOver as Guard, flush }); int index = -1; int filling = 0; int[] counter = { 0, 0, 0, 0 }; const int NEED = 0; const int OVER = 1; const int FLUSH = 2; Boolean[] preCon = new Boolean[3]; preCon[NEED] = true; preCon[OVER] = true; preCon[FLUSH] = false; openForBusiness.read(); int removing = 0; while (true) { index = vAlt.select(preCon); switch (index) { case NEED: needToConsult.read(); joinGroup.write(filling); counter[filling] = counter[filling] + 1; if (counter[filling] == 3) { filling = (filling + 1) % 4; } break; case OVER: consultationOver.read(); removing = (removing + 1) % 4; break; case FLUSH: groups[removing].flush(); counter[removing] = 0; break; } preCon[FLUSH] = (groups[removing].holding() == 3); // have to ensure that the the last elf to fallInto a bucket // has actually done so // we do not rely on the fact that the coounter for the bucket has reached 3 // we test to make sure there are three processes in the bucket // which is next to be removed // changed as a result of the discussion at CPA2008 Fringe session from // preCon[FLUSH] = (counter[removing] == 3) } }
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() { toConsole.write("Please input reset values\n"); while (true) { var v = fromConverter.read(); toClearOutput.write("\n"); resetValue.write(v); } }
public void run() { var alt = new Alternative(new Guard[] { resetChannel as Guard, inChannel as Guard }); outChannel.write(prefixValue); while (true) { int index = alt.priSelect(); if (index == 0) { var resetValue = resetChannel.read(); inChannel.read(); outChannel.write(resetValue); } else { outChannel.write(inChannel.read()); } } }
public void run() { int i = 1000; while (i > 0) { i = (int)inChannel.read(); Console.WriteLine("\nThe input was " + i); } Console.WriteLine("Finished!"); }
/** * The main body of this process. */ public void run() { CSTimer tim = new CSTimer(); while (true) { Object o = In.read(); //Debug.WriteLine("Fixed delay sleeping for " + delayTime); tim.sleep(delayTime); Out.write(o); } }
public void run() { ProcessWrite[] parWrite = { new ProcessWrite(out1), new ProcessWrite(out2) }; CSPParallel par = new CSPParallel(parWrite); while (true) { Object value = In.read(); parWrite[0].value = value; parWrite[1].value = value; par.run(); } }
/** * The main body of this process. */ public /*synchronized*/ void run() { try { while (true) { printStream.Write(prefix); printStream.Write(In.read()); printStream.Write(postfix); printStream.Flush(); } } catch (PoisonException p) { // nothing to do } }
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; } } }
public void run() { Random rng = new Random(); CSTimer timer = new CSTimer(); while (true) { Console.WriteLine("\t\tReindeer" + number + ": on holiday ... wish you were here, :)"); timer.sleep(holidayTime + rng.Next(holidayTime)); Console.WriteLine("\t\tReindeer " + number + ": back from holiday ... ready for work, :("); stable.sync(); harness.write(number); harnessed.read(); Console.WriteLine("\t\tReindeer " + number + ": delivering toys ... la-di-da-di-da-di-da, :)"); returned.read(); Console.WriteLine("\t\tReindeer " + number + ": all toys delivered ... want a holiday, :("); unharness.read(); } }
public void run() { long[] sample = { 1000, 250, 100 }; int[] count = { 10, 40, 100 }; while (true) { for (int cycle = 0; cycle < sample.Length; cycle++) { reset.write(sample[cycle]); Console.WriteLine("\nSampling every " + sample[cycle] + " ms ...\n"); for (int i = 0; i < count[cycle]; i++) { int n = (int)c.read(); Console.WriteLine("\t==> " + n); } } } }
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() { 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() { Random rng = new Random(); CSTimer timer = new CSTimer(); while (true) { Console.WriteLine("\tElf " + number + ": working, :)"); timer.sleep(workingTime + rng.Next(workingTime)); needToConsult.write(number); int group = (int)joinGroup.read(); groups[group].fallInto(); // process will wait until flushed by vestibule // it is guaranteed by vestibule that three Elf proceses will be started consult.write(number); Console.WriteLine("\tElf " + number + ": need to consult Santa, :("); consulting.read(); Console.WriteLine("\tElf " + number + ": about these toys ... ???"); negotiating.write(1); consulted.read(); Console.WriteLine("\tElf " + number + ": OK ... we will build it, bye, :("); } }
protected void release() { synchIn.read(); }
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 } }
public void run() { const int REINDEER = 0; const int ELVES = 1; Random rng = new Random(); CSTimer timer = new CSTimer(); Alternative santaAlt = new Alternative(new Guard[] { stable, consult as Guard }); openForBusiness.write(1); int index = -1; while (true) { index = santaAlt.priSelect(); int[] id = new int[9]; //size of the array must be provided. For loops no greater than 9 - Karol Pasierb switch (index) { case REINDEER: Console.WriteLine("Santa: ho-ho-ho ... the reindeer are back"); for (int i = 0; i < 9; i++) { ; id[i] = (int)harness.read(); Console.WriteLine("Santa: harnessing reindeer " + id[i] + " ..."); } Console.WriteLine("Santa: mush mush ..."); for (int i = 0; i < 9; i++) { harnessed.write(1); } // simulate time to undertake present deliveries timer.sleep(deliveryTime + rng.Next(deliveryTime)); Console.WriteLine("Santa: woah ... we are back home"); for (int i = 0; i < 9; i++) { returned.write(1); } for (int i = 0; i < 9; i++) { Console.WriteLine("Santa: unharnessing reindeer " + id[i]); unharnessList[id[i]].write(1); } break; case ELVES: id[0] = (int)consult.read(); for (int i = 1; i < 3; i++) { id[i] = (int)consult.read(); } Console.WriteLine("Santa: ho-ho-ho ... some elves are here!"); for (int i = 0; i < 3; i++) { consulting[id[i]].write(1); Console.WriteLine("Santa: hello elf " + id[i] + " ..."); } for (int i = 0; i < 3; i++) { negotiating.read(); } Console.WriteLine("Santa: consulting with elves ..."); timer.sleep(consultationTime + rng.Next(consultationTime)); Console.WriteLine("Santa: OK, all done - thanks!"); for (int i = 0; i < 3; i++) { consulted[id[i]].write(1); Console.WriteLine("Santa: goodbye elf " + id[i] + " ..."); } consultationOver.write(1); break; } } }
/** * The main body of this process. */ public void run() { value = inChannel.read(); }
/** * Reads a value from the channel. * * @see jcsp.lang.ChannelInput * @return the value read. */ public Object read() { return(In.read()); }