|
Spreadsheet Toolkit | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--corpus.fileIO.Semaphore
A Semaphore is used for synchronization of Java threads. A Semaphore has an integer value. A thread can increment the value by calling up(). A thread can decrement the value by calling down(). A thread that invokes down() waits until the value is positive before decrementing the value. A semaphore has a name which is determined by the string argument of its constructor. A semaphore can be created for granting permission by invoking the constructor with an argument of 0. If thread A needs to be held up until thread B is ready then A invokes down() and B invokes up() when it is ready(). This increments the semaphore value, allowing A to proceed. A semaphore can also be created for enforcing mutual exclusion by invoking the constructor with an argument of 1. Threads call down() when entering a critical code section and up() when leaving. This ensures that only one thread can be executing critical section code at a time. Finally, a semaphore can be used for resource counting. For this use, the semaphore is created by calling the constructor with an argument equal to the initial number of instances of the counted resource. A thread invokes down() when acquiring an instance of the resource and invokes up() when releasing an instance.
Constructor Summary | |
Semaphore()
|
Method Summary | |
void |
P()
P for Wait() because P is the first letter of the Dutch word "passeren," which means "to pass," |
void |
V()
V for Signal() because V is the first letter of the Dutch word "vrijgeven," which means "to release." |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public Semaphore()
Method Detail |
public void P()
public void V()
|
Spreadsheet Toolkit | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |