|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnachos.machine.NachosThread
public class NachosThread
Nachos threads class. Threads are the units of concurrent activity in an operating system, and support for threads would usually be found in one of the lowest layers of the kernel. In a real operating system, a thread is represented as an object that has space to hold a "snapshot" of the state of the thread when it is not running. This snapshot includes the contents of the CPU registers (including the program counter and stack pointer), and a reference to a region of memory private to the thread that it uses as its stack. Switching the CPU between threads requires direct access to the CPU registers. Since this is not usually possible in a higher-level programming language, the context switch routine is generally programmed in assembly language. In Java, there isn't any way for us to manipulate registers and stacks so that we can implement our own threads support from scratch. That's too bad, because it is very instructive to see how this is actually accomplished. But since we can't do our own threads implementation, we just implement Nachos threads on top of the thread support that already exists in Java.
Field Summary | |
---|---|
static int |
BLOCKED
Status of a thread that is waiting for some event to occur. |
static int |
JUST_CREATED
Status of a thread that has just been created and is not yet runnable. |
static int |
READY
Status of a thread that is ready to use the CPU but not now running. |
static int |
RUNNING
Status of the thread that is currently using the CPU. |
static int |
TERMINATED
Setting the status of a thread to this causes it to terminate. |
Constructor Summary | |
---|---|
NachosThread(java.lang.String threadName)
Create a new Nachos thread object, without specifying an entry point. |
|
NachosThread(java.lang.String threadName,
java.lang.Runnable runObj)
Create a new Nachos thread object. |
Method Summary | |
---|---|
java.lang.String |
getName()
Get the name of this thread. |
int |
getStatus()
Method used to get the current status of a thread. |
void |
restoreState()
Restore the state of a thread on a context switch. |
void |
saveState()
Save the state of a thread on a context switch. |
void |
setRunnable(java.lang.Runnable runObj)
This method is used to set the entry point for a NachosThread. |
void |
setStatus(int st)
Method used to set the current status (ready, running, blocked, etc.) of a thread. |
void |
switchTo(NachosThread newThread)
This method is used by the Scheduler to switch execution to a new thread. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int JUST_CREATED
public static final int RUNNING
public static final int READY
public static final int BLOCKED
public static final int TERMINATED
Constructor Detail |
---|
public NachosThread(java.lang.String threadName, java.lang.Runnable runObj)
threadName
- An arbitrary name, useful for debugging.runObj
- Execution of the thread will begin with the run()
method of this object.public NachosThread(java.lang.String threadName)
threadName
- An arbitrary name, useful for debugging.Method Detail |
---|
public void setStatus(int st)
st
- The new status of the thread.public int getStatus()
public void saveState()
public void restoreState()
public void setRunnable(java.lang.Runnable runObj)
runObj
- Execution of the thread will begin with the run()
method of this object.public void switchTo(NachosThread newThread)
newThread
- The thread to switch to.public java.lang.String getName()
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |