|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnachos.threads.Semaphore
public class Semaphore
A Semaphore is a synchronization primitive with an unsigned value. A semaphore has only two operations:
Note that this API does not allow a thread to read the value of the semaphore directly. Even if you did read the value, the only thing you would know is what the value used to be. You don't know what the value is now, because by the time you get the value, a context switch might have occurred, and some other thread might have called P() or V(), so the true value might now be different.
Constructor Summary | |
---|---|
Semaphore(int initialValue)
Allocate a new semaphore. |
Method Summary | |
---|---|
void |
P()
Atomically wait for this semaphore to become non-zero and decrement it. |
static void |
selfTest()
Test if this module is working. |
void |
V()
Atomically increment this semaphore and wake up at most one other thread sleeping on this semaphore. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Semaphore(int initialValue)
initialValue
- the initial value of this semaphore.Method Detail |
---|
public void P()
public void V()
public static void selfTest()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |