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

📄 semaphore.java

📁 java实现的一个pascal编译器
💻 JAVA
字号:
/**
 * File : Semaphore.java
 * Author : Fidel Viegas (viegasfh@hotmail.com)
 * Date : 23/02/2000
 */
package uk.co.brainycreatures.jpascal.type;

public class Semaphore {
  private long value; // value of semaphore

  // constructor for binary semaphores
  public Semaphore() {
    value = 0;
  }

  // constructor for counting semaphores
  public Semaphore(long initial) {
    value = initial; // initial value of the semaphore
  }
    
  // if the value of the semaphore is
  // greater than zero, then its value is decremented
  // by one
  public synchronized void Wait() {
    while (value <= 0) {
      try {
        wait();
      }
      catch (InterruptedException e) {
      }
    }
    value--;
  }

  // if the processes are blocked on the semaphore,
  // then unblock one of them
  public synchronized void Signal() {
    value++;
    notify(); // notify the process
  }
}

      

⌨️ 快捷键说明

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