예제 #1
0
  /**
   * Finish the current thread and schedule it to be destroyed when it is safe to do so. This method
   * is automatically called when a thread's <tt>run</tt> method returns, but it may also be called
   * directly.
   *
   * <p>The current thread cannot be immediately destroyed because its stack and other execution
   * state are still in use. Instead, this thread will be destroyed automatically by the next thread
   * to run, when it is safe to delete this thread.
   */
  public static void finish() {
    Lib.debug(dbgThread, "Finishing thread: " + currentThread.toString());

    Machine.interrupt().disable();

    Machine.autoGrader().finishingCurrentThread();

    Lib.assertTrue(toBeDestroyed == null);
    toBeDestroyed = currentThread;

    currentThread.status = statusFinished;

    KThread aux = null;
    if (joinList.size() > 0) {
      aux = joinList.getFirst();
    }
    if (aux != null) {
      aux.ready();
      joinList.removeFirst();
    }
    sleep();
  }
예제 #2
0
  /** Determine the next thread to run, then dispatch the CPU to the thread using <tt>run()</tt>. */
  private static void runNextThread() {
    KThread nextThread = readyQueue.nextThread();
    if (nextThread == null) nextThread = idleThread;

    nextThread.run();
  }