nachos.threads
Class PriorityScheduler.PriorityQueue

java.lang.Object
  extended by nachos.threads.ThreadQueue
      extended by nachos.threads.PriorityScheduler.PriorityQueue
Enclosing class:
PriorityScheduler

protected class PriorityScheduler.PriorityQueue
extends ThreadQueue

A ThreadQueue that sorts threads by priority.


Field Summary
 boolean transferPriority
          true if this queue should transfer priority from waiting threads to the owning thread.
 
Method Summary
 void acquire(KThread thread)
          Notify this thread queue that a thread has received access, without going through request() and nextThread().
 KThread nextThread()
          Notify this thread queue that another thread can receive access.
protected  PriorityScheduler.ThreadState pickNextThread()
          Return the next thread that nextThread() would return, without modifying the state of this queue.
 void print()
          Print out all the threads waiting for access, in no particular order.
 void waitForAccess(KThread thread)
          Notify this thread queue that the specified thread is waiting for access.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

transferPriority

public boolean transferPriority
true if this queue should transfer priority from waiting threads to the owning thread.

Method Detail

waitForAccess

public void waitForAccess(KThread thread)
Description copied from class: ThreadQueue
Notify this thread queue that the specified thread is waiting for access. This method should only be called if the thread cannot immediately obtain access (e.g. if the thread wants to acquire a lock but another thread already holds the lock).

A thread must not simultaneously wait for access to multiple resources. For example, a thread waiting for a lock must not also be waiting to run on the processor; if a thread is waiting for a lock it should be sleeping.

However, depending on the specific objects, it may be acceptable for a thread to wait for access to one object while having access to another. For example, a thread may attempt to acquire a lock while holding another lock. Note, though, that the processor cannot be held while waiting for access to anything else.

Specified by:
waitForAccess in class ThreadQueue
Parameters:
thread - the thread waiting for access.

acquire

public void acquire(KThread thread)
Description copied from class: ThreadQueue
Notify this thread queue that a thread has received access, without going through request() and nextThread(). For example, if a thread acquires a lock that no other threads are waiting for, it should call this method.

This method should not be called for a thread returned from nextThread().

Specified by:
acquire in class ThreadQueue
Parameters:
thread - the thread that has received access, but was not returned from nextThread().

nextThread

public KThread nextThread()
Description copied from class: ThreadQueue
Notify this thread queue that another thread can receive access. Choose and return the next thread to receive access, or null if there are no threads waiting.

If the limited access object transfers priority, and if there are other threads waiting for access, then they will donate priority to the returned thread.

Specified by:
nextThread in class ThreadQueue
Returns:
the next thread to receive access, or null if there are no threads waiting.

pickNextThread

protected PriorityScheduler.ThreadState pickNextThread()
Return the next thread that nextThread() would return, without modifying the state of this queue.

Returns:
the next thread that nextThread() would return.

print

public void print()
Description copied from class: ThreadQueue
Print out all the threads waiting for access, in no particular order.

Specified by:
print in class ThreadQueue