Exemplo n.º 1
0
  /**
   * Allocate a new <tt>KThread</tt>. If this is the first <tt>KThread</tt>, create an idle thread
   * as well.
   */
  public KThread() {
    if (currentThread != null) {
      tcb = new TCB();
    } else {
      readyQueue = ThreadedKernel.scheduler.newThreadQueue(false);
      readyQueue.acquire(this);

      currentThread = this;
      tcb = TCB.currentTCB();
      name = "main";
      restoreState();

      createIdleThread();
    }
  }
Exemplo n.º 2
0
  /**
   * Prepare this thread to be run. Set <tt>status</tt> to <tt>statusRunning</tt> and check
   * <tt>toBeDestroyed</tt>.
   */
  protected void restoreState() {
    Lib.debug(dbgThread, "Running thread: " + currentThread.toString());

    Lib.assertTrue(Machine.interrupt().disabled());
    Lib.assertTrue(this == currentThread);
    Lib.assertTrue(tcb == TCB.currentTCB());

    Machine.autoGrader().runningThread(this);

    status = statusRunning;

    if (toBeDestroyed != null) {
      toBeDestroyed.tcb.destroy();
      toBeDestroyed.tcb = null;
      toBeDestroyed = null;
    }
  }