public void run() { int n = 1 * num; CSTimer timer = new CSTimer(); Random rnd = new Random(); int randomTimeout = rnd.Next(1, 10) * 500; Alternative barrierGroupAlt = new Alternative(new Guard[] { input, barrier }); const int INPUT = 0, GROUP = 1, TIMER = 2; output.write(n.ToString()); while (true) { bool pending = input.pending(); while (!pending) { Debug.WriteLine((char)num + " pending = " + pending); n++; output.write((char)num + " " + n.ToString()); // work with the barrier pending = input.pending(); } input.read(); // must consume the input output.write("Read click " + n.ToString()); // work with the barrier Boolean group = true; while (group) { switch (barrierGroupAlt.priSelect()) { case INPUT: Debug.WriteLine((char)num + "barier input"); string x = input.read().ToString(); // must consume the input Console.WriteLine(x); group = false; // end barrier working break; case GROUP: n--; // work with the barrier output.write(n.ToString()); // work with the barrier Debug.WriteLine((char)num + "barier wrote " + n); break; } } } }
public void run() { /*final*/ Alternative clickGroup = new Alternative(new Guard[] { click, group }); const int CLICK = 0, GROUP = 1; int n = 0; configure.write(n.ToString()); while (true) { configure.write(Color.Green); // pretty while (!click.pending()) { n++; // work on our own configure.write(n.ToString()); // work on our own } click.read(); // must consume the click configure.write(Color.Red); // pretty Boolean group = true; while (group) { switch (clickGroup.priSelect()) { case CLICK: click.read(); // must consume the click group = false; // end group working break; case GROUP: n--; // work with the group configure.write(n.ToString()); // work with the group break; } } } }
/** * Returns whether there is an open() pending on this connection. <p> * * <i>Note: if there is, it won't go away until you accept it. But if * there isn't, there may be one by the time you check the result of * this method.</i> * * @return true only if open() will complete without blocking. */ public Boolean pending() { return(altingChannel.pending()); }
/** * Returns whether there is data pending on this channel. * <P> * <I>Note: if there is, it won't go away until you read it. But if there * isn't, there may be some by the time you check the result of this method.</I> * * @return state of the channel. */ public override Boolean pending() { return(channel.pending()); }