1117. H2O 生成
作者:
上杉丶零 | 来源:发表于
2020-03-19 17:04 被阅读0次class H2O {
private Semaphore h;
private Semaphore o;
public H2O() {
h = new Semaphore(2);
o = new Semaphore(0);
}
public void hydrogen(Runnable releaseHydrogen) throws InterruptedException {
h.acquire();
// releaseHydrogen.run() outputs "H". Do not change or remove this line.
releaseHydrogen.run();
o.release();
}
public void oxygen(Runnable releaseOxygen) throws InterruptedException {
o.acquire(2);
// releaseOxygen.run() outputs "O". Do not change or remove this line.
releaseOxygen.run();
h.release(2);
}
}
![](https://img.haomeiwen.com/i13134428/f47c408afbac849f.png)
image.png
本文标题:1117. H2O 生成
本文链接:https://www.haomeiwen.com/subject/cavlyhtx.html
网友评论