|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnachos.kernel.threads.Condition
public class Condition
This class defines a "condition variable". A condition variable does not have a value, but threads may be queued, waiting on the variable. The following are the only operations on a condition variable: await() -- release the lock, relinquish the CPU until signaled, then re-acquire the lock signal() -- wake up a thread, if there are any waiting on the condition broadcast() -- wake up all threads waiting on the condition All operations on a condition variable must be made while the current thread has acquired a lock. Indeed, all accesses to a given condition variable must be protected by the same lock. In other words, mutual exclusion must be enforced among threads calling the condition variable operations. In Nachos, condition variables are assumed to obey *Mesa*-style semantics. When a Signal or Broadcast wakes up another thread, it simply puts the thread on the ready list, and it is the responsibility of the woken thread to re-acquire the lock (this re-acquire is taken care of within await()). By contrast, some define condition variables according to *Hoare*-style semantics -- where the signalling thread gives up control over the lock and the CPU to the woken thread, which runs immediately and gives back control over the lock to the signaller when the woken thread leaves the critical section. The consequence of using Mesa-style semantics is that some other thread can acquire the lock, and change data structures, before the woken thread gets a chance to run.
Field Summary | |
---|---|
private Lock |
conditionLock
The lock associated with this condition. |
java.lang.String |
name
Printable name useful for debugging. |
private List |
waitingThreads
Who's waiting on this condition? |
Constructor Summary | |
---|---|
Condition(java.lang.String debugName,
Lock lock)
Initialize a new condition variable. |
Method Summary | |
---|---|
void |
await()
Wait on a condition until signalled. |
void |
broadcast()
Wake up all threads waiting on the condition. |
Lock |
getLock()
Accessor to obtain the lock associated with a condition. |
void |
signal()
Wake up a thread, if any, that is waiting on the condition. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public final java.lang.String name
private Lock conditionLock
private List waitingThreads
Constructor Detail |
---|
public Condition(java.lang.String debugName, Lock lock)
debugName
- An arbitrary name, useful for debugging.lock
- A lock to be associated with this condition.Method Detail |
---|
public Lock getLock()
public void await()
public void signal()
public void broadcast()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |