semaphore.java

来自「本程序是国外经典的操作系统调度试验」· Java 代码 · 共 34 行

JAVA
34
字号
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 + =
减小字号Ctrl + -
显示快捷键?