nachos.kernel.threads
Class Condition

java.lang.Object
  extended by nachos.kernel.threads.Condition

public class Condition
extends java.lang.Object

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

name

public final java.lang.String name
Printable name useful for debugging.


conditionLock

private Lock conditionLock
The lock associated with this condition.


waitingThreads

private List waitingThreads
Who's waiting on this condition?

Constructor Detail

Condition

public Condition(java.lang.String debugName,
                 Lock lock)
Initialize a new condition variable.

Parameters:
debugName - An arbitrary name, useful for debugging.
lock - A lock to be associated with this condition.
Method Detail

getLock

public Lock getLock()
Accessor to obtain the lock associated with a condition.

Returns:
the lock associated with this condition.

await

public void await()
Wait on a condition until signalled. The caller must hold the lock associated with the condition. The lock is released, and the caller relinquishes the CPU until it is signalled by another thread that calls signal or broadcast on the same condition.


signal

public void signal()
Wake up a thread, if any, that is waiting on the condition.


broadcast

public void broadcast()
Wake up all threads waiting on the condition.