Package BSsync
Class Semaphore
- java.lang.Object
-
- BSsync.Semaphore
-
public class Semaphore extends java.lang.Object
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
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
acquire()
Wait until a permit is available, and take onevoid
release()
Release a permit
-
-
-
Constructor Detail
-
Semaphore
public Semaphore(int initialPermits)
Create a Semaphore with the given initial number of permits. Using a seed of one makes the semaphore act as a mutual exclusion lock. Negative seeds are also allowed, in which case no acquires will proceed until the number of releases has pushed the number of permits past 0.- Parameters:
initialPermits
- initial value of the Semaphore
-
Semaphore
public Semaphore(int initialPermits, java.lang.String name)
Create a named Semaphore with the given initial number of permits. the name is only used for debugging output. Using a seed of one makes the semaphore act as a mutual exclusion lock. Negative seeds are also allowed, in which case no acquires will proceed until the number of releases has pushed the number of permits past 0.- Parameters:
initialPermits
- initial value of the Semaphorename
- name of the Semaphore
-
-