|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object BSsync.Semaphore
public class Semaphore
Base class for counting semaphores. Conceptually, a semaphore maintains a set of permits. Each acquire() blocks if necessary until a permit is available, and then takes it. Each release adds a permit. However, no actual permit objects are used; the Semaphore just keeps a count of the number available and acts accordingly.
A semaphore initialized to 1 can serve as a mutual exclusion lock.
This implementation makes NO guarantees about the order in which threads will acquire permits
Field Summary | |
---|---|
protected int |
permits_
current number of available permits |
static boolean |
verbose
Set this variable to true for debugging output |
Constructor Summary | |
---|---|
Semaphore(int initialPermits)
Create a Semaphore with the given initial number of permits. |
|
Semaphore(int initialPermits,
java.lang.String name)
Create a named Semaphore with the given initial number of permits. |
Method Summary | |
---|---|
void |
acquire()
Wait until a permit is available, and take one |
void |
release()
Release a permit |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static boolean verbose
protected int permits_
Constructor Detail |
---|
public Semaphore(int initialPermits)
initialPermits
- initial value of the Semaphorepublic Semaphore(int initialPermits, java.lang.String name)
initialPermits
- initial value of the Semaphorename
- name of the SemaphoreMethod Detail |
---|
public void acquire()
public void release()
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |