|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnachos.kernel.threads.Scheduler
public class Scheduler
The scheduler is responsible for maintaining a list of threads that are ready to run and for choosing the next thread to run. These routines assume that interrupts are already disabled. If interrupts are disabled, we can assume mutual exclusion (since we are on a uniprocessor). NOTE: We can't use Locks to provide mutual exclusion here, since if we needed to wait for a lock, and the lock was busy, we would end up calling findNextToRun(), and that would put us in an infinite loop. Very simple implementation -- no priorities, straight FIFO. Might need to be improved in later assignments.
Nested Class Summary | |
---|---|
private static class |
Scheduler.TimerInterruptHandler
Interrupt handler for the timer device. |
Field Summary | |
---|---|
private static nachos.machine.NachosThread |
currentThread
The currently running thread, or null, if none. |
private static List |
readyList
Queue of threads that are ready to run, but not running. |
private static nachos.machine.NachosThread |
threadToBeDestroyed
Terminated thread awaiting reclamation of its stack. |
private static nachos.machine.Timer |
timer
The timer used to implement time slicing. |
Constructor Summary | |
---|---|
Scheduler()
|
Method Summary | |
---|---|
static nachos.machine.NachosThread |
currentThread()
Accessor method for accessing the current thread. |
private static nachos.machine.NachosThread |
findNextToRun()
Return the next thread to be scheduled onto the CPU. |
static void |
finish()
Called by a thread to terminate itself. |
static void |
init(java.lang.String[] args)
Initialize the scheduler. |
static void |
readyToRun(nachos.machine.NachosThread thread)
Mark a thread as ready, but not running, and put it on the ready list for later scheduling onto the CPU. |
private static void |
run(nachos.machine.NachosThread nextThread)
Dispatch the CPU to nextThread. |
static void |
setRandomYield(boolean on)
Called to turn on or off a timer that forces a context switch at random intervals. |
static void |
sleep()
Relinquish the CPU, because the current thread is blocked waiting on a synchronization variable (Semaphore, Lock, or Condition). |
static void |
start()
Called by a Java thread (usually the initial thread that calls Nachos.main) to start the first Nachos thread. |
static void |
yield()
Relinquish the CPU if any other thread is ready to run. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static List readyList
private static nachos.machine.NachosThread currentThread
private static nachos.machine.NachosThread threadToBeDestroyed
private static nachos.machine.Timer timer
Constructor Detail |
---|
public Scheduler()
Method Detail |
---|
public static nachos.machine.NachosThread currentThread()
public static void init(java.lang.String[] args)
public static void start()
public static void readyToRun(nachos.machine.NachosThread thread)
thread
- The thread to be put on the ready list.private static nachos.machine.NachosThread findNextToRun()
private static void run(nachos.machine.NachosThread nextThread)
nextThread
- The thread to be given the CPU.public static void yield()
public static void sleep()
public static void finish()
public static void setRandomYield(boolean on)
on
- True if the timer is to be turned on.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |