Blame view
circus/src/jcircus/tests/TestCSTimer.java
2.53 KB
8d0dc533f
![]() |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
package jcircus.tests; import org.jcsp.lang.Alternative; import org.jcsp.lang.AltingBarrier; import org.jcsp.lang.Any2OneChannel; import org.jcsp.lang.CSProcess; import org.jcsp.lang.CSTimer; import org.jcsp.lang.Channel; import org.jcsp.lang.Guard; import org.jcsp.lang.One2OneChannel; import org.jcsp.lang.One2OneChannelSymmetric; import org.jcsp.lang.Parallel; public class TestCSTimer { static CSTimer timer = new CSTimer (); Any2OneChannel chan = Channel.any2one(); Any2OneChannel chan2 = Channel.any2one(); static AltingBarrier [] b = AltingBarrier.create(2); public class P implements CSProcess { public void run() { b [1].sync(); } } public class R implements CSProcess { public void run() { chan.out().write(new Integer (5)); //int x = (Integer)chan.in().read(); } } public class S implements CSProcess { public void run() { boolean success = false; //int var = (Integer)chan.in().read(); Guard[] guards = new Guard [] {chan.in(), chan2.in()}; Alternative alt = new Alternative (guards); int select = alt.select(); //System.out.println ("Var: " + var); /*while (!success) { org.jcsp.lang.Guard [] guard = new org.jcsp.lang.Guard [] {timer, chan.in()}; org.jcsp.lang.Alternative alt = new org.jcsp.lang.Alternative (guard); int x = alt.select(); if (x != 0) success = true; System.out.println ("Select Chan = " + x); }*/ } } public class Q implements CSProcess { public void run() { boolean success = false; while (!success) { org.jcsp.lang.Guard [] guard = new org.jcsp.lang.Guard [] {b [0], /*b[1],*/ timer}; org.jcsp.lang.Alternative alt = new org.jcsp.lang.Alternative (guard); int x = alt.select(); if (x == 0) success = true; System.out.println ("Select Barrier = " + x); } } } public static void main (String [] args) { /* timer.setAlarm(1000); TestCSTimer test = new TestCSTimer (); TestCSTimer.P p = test.new P (); TestCSTimer.Q q = test.new Q (); TestCSTimer.R r = test.new R (); TestCSTimer.S s = test.new S (); */ //Parallel par = new Parallel (new CSProcess [] {p, q}); //par.run(); //Parallel par2 = new Parallel (new CSProcess [] {r, s}); //par2.run(); System.out.println("INICIO"); One2OneChannelSymmetric cc = Channel.one2oneSymmetric(); SS ss = new SS(cc.in()); RR rr = new RR(cc.out()); System.out.println("MEIO"); Parallel par = new Parallel (new CSProcess [] {rr, ss}); par.run(); System.out.println("FIM"); } } |