⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 security.java

📁 升级版本
💻 JAVA
字号:
import org.jcsp.lang.Alternative;import org.jcsp.lang.AltingChannelInput;import org.jcsp.lang.CSProcess;import org.jcsp.lang.ChannelOutput;import org.jcsp.lang.Guard;class Security implements CSProcess {  // protected attributes  protected AltingChannelInput down, up;  protected ChannelOutput report;  protected static final int maxSitting = 4;  protected SecurityReport[] seated = new SecurityReport[maxSitting + 1];  // constructors  public Security (AltingChannelInput down, AltingChannelInput up,                   ChannelOutput report) {    this.down = down;    this.up = up;    this.report = report;    for (int i = 0; i < (maxSitting + 1); i++) {      seated[i] = new SecurityReport (i);    }  }  // public methods  public void run () {    Alternative alt = new Alternative (new Guard[] {down, up});    boolean[] precondition = {true, true};    final int DOWN = 0;    final int UP = 1;    int nSitting = 0;    int philId;    while (true) {      precondition[DOWN] = (nSitting < maxSitting);      switch (alt.fairSelect (precondition)) {        case DOWN:          philId = ((Integer) down.read ()).intValue();          nSitting++;          report.write (seated[nSitting]);        break;        case UP:          philId = ((Integer) up.read ()).intValue();          nSitting--;          report.write (seated[nSitting]);        break;      }    }  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -