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

📄 semaphore.java

📁 Reader Writer Problem to solve synchronization issues
💻 JAVA
字号:
/* $Id: Semaphore.java,v 1.2 1996/06/28 04:10:16 kmillik1 Exp $ *//* $Log: Semaphore.java,v $# Revision 1.2  1996/06/28  04:10:16  kmillik1# Fixed $Log$ comment.## Revision 1.1  1996/06/28  04:03:02  kmillik1# Initial revision#*/public class Semaphore extends Object {  private int s;  public Semaphore(int n) {    s = n;//	System.out.println("Semaphore");  }    public Semaphore() {    this(0);  }  synchronized public void up() {	int temp;	temp=s;	s=1;//System.out.println("up value: "+s);	if(temp==0){notify(); //	System.out.println("notified up value: "+s);	};  }  synchronized public void down() {    try {      if (s > 0){	s=0;//	System.out.println("down value: "+s);}      else{//	System.out.print("down value: "+s);//	System.out.println(" Waiting..");	wait();	s=0;};    }    catch (InterruptedException e) {      // add exception handler code here    }  }}    

⌨️ 快捷键说明

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