nachos.machine
Class TCB

java.lang.Object
  extended by nachos.machine.TCB

public final class TCB
extends Object

A TCB simulates the low-level details necessary to create, context-switch, and destroy Nachos threads. Each TCB controls an underlying JVM Thread object.

Do not use any methods in java.lang.Thread, as they are not compatible with the TCB API. Most Thread methods will either crash Nachos or have no useful effect.

Do not use the synchronized keyword anywhere in your code. It's against the rules, and it can easily deadlock nachos.


Field Summary
static int maxThreads
          The maximum number of started, non-destroyed TCB's that can be in existence.
 
Constructor Summary
TCB()
          Allocate a new TCB.
 
Method Summary
 void contextSwitch()
          Context switch between the current TCB and this TCB.
static TCB currentTCB()
          Return the TCB of the currently running thread.
 void destroy()
          Destroy this TCB.
static void die()
          Destroy all TCBs and exit Nachos.
static void givePrivilege(Privilege privilege)
          Give the TCB class the necessary privilege to create threads.
static boolean isNachosThread()
          Test if the current JVM thread belongs to a Nachos TCB.
 void start(Runnable target)
          Causes the thread represented by this TCB to begin execution.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

maxThreads

public static final int maxThreads
The maximum number of started, non-destroyed TCB's that can be in existence.

See Also:
Constant Field Values
Constructor Detail

TCB

public TCB()
Allocate a new TCB.

Method Detail

givePrivilege

public static void givePrivilege(Privilege privilege)
Give the TCB class the necessary privilege to create threads. This is necessary, because unlike other machine classes that need privilege, we want the kernel to be able to create TCB objects on its own.

Parameters:
privilege - encapsulates privileged access to the Nachos machine.

start

public void start(Runnable target)
Causes the thread represented by this TCB to begin execution. The specified target is run in the thread.


currentTCB

public static TCB currentTCB()
Return the TCB of the currently running thread.


contextSwitch

public void contextSwitch()
Context switch between the current TCB and this TCB. This TCB will become the new current TCB. It is acceptable for this TCB to be the current TCB.


destroy

public void destroy()
Destroy this TCB. This TCB must not be in use by the current thread. This TCB must also have been authorized to be destroyed by the autograder.


die

public static void die()
Destroy all TCBs and exit Nachos. Same as Machine.terminate().


isNachosThread

public static boolean isNachosThread()
Test if the current JVM thread belongs to a Nachos TCB. The AWT event dispatcher is an example of a non-Nachos thread.

Returns:
true if the current JVM thread is a Nachos thread.