?? semaphore.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 + -