📄 diningphilosopherscollege.java
字号:
import org.jcsp.lang.Any2OneChannel;import org.jcsp.lang.CSProcess;import org.jcsp.lang.ChannelOutput;import org.jcsp.lang.One2OneChannel;import org.jcsp.lang.Parallel;import org.jcsp.lang.Channel;class DiningPhilosophersCollege implements CSProcess { private final int nPhilosophers; private final ChannelOutput report; public DiningPhilosophersCollege (int nPhilosophers, ChannelOutput report) { this.nPhilosophers = nPhilosophers; this.report = report; } public void run () { final One2OneChannel[] left = Channel.one2oneArray(nPhilosophers); final One2OneChannel[] right = Channel.one2oneArray(nPhilosophers); final Any2OneChannel down = Channel.any2one(); final Any2OneChannel up = Channel.any2one(); final Fork[] fork = new Fork[nPhilosophers]; for (int i = 0; i < nPhilosophers; i++) { fork[i] = new Fork (nPhilosophers, i, left[i].in(), right[(i + 1)%nPhilosophers].in(), report); } final Philosopher[] phil = new Philosopher[nPhilosophers]; for (int i = 0; i < nPhilosophers; i++) { phil[i] = new Philosopher (i, left[i].out(), right[i].out(), down.out(), up.out(), report); } new Parallel ( new CSProcess[] { new Parallel (phil), new Parallel (fork), new Security (down.in(), up.in(), report), new Clock (report) } ).run (); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -