📄 semaphore.java
字号:
import java.util.Vector ;public class Semaphore { private int value ; private Vector queue ; public Semaphore(int i) { value = i ; queue = new Vector() ; }// This should be called V() in usual semaphore parlance, but// it was called signal() last year, and the decision to use the// proper names for the operations was taken after the lab manual// was printed. So we will stick with signal()! public synchronized void signal() { // you need to write this }// This should be called P() in usual semaphore parlance ... // but the above explanation applies. public void wait(SemProc t) { // you need to write this too. Note it is not synchronized // because it may end by removing the current process, t, // from the ready queue and that would leave the semaphore locked! // However it IS important to exclude the possibility that two // processes could confuse each other - even though this is only a // theorectical possibility. You will not observe it "going wrong" // in the lab configuration - but you will lose a mark of you don't // get it right! }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -