/** Moves this thread to the ready state and adds this to the scheduler's ready queue. */ public void ready() { Lib.debug(dbgThread, "Ready thread: " + toString()); Lib.assertTrue(Machine.interrupt().disabled()); Lib.assertTrue(status != statusReady); status = statusReady; if (this != idleThread) readyQueue.waitForAccess(this); Machine.autoGrader().readyThread(this); }
/** * 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; sleep(); }
/** * Create the idle thread. Whenever there are no threads ready to be run, and * <tt>runNextThread()</tt> is called, it will run the idle thread. The idle thread must never * block, and it will only be allowed to run when all other threads are blocked. * * <p>Note that <tt>ready()</tt> never adds the idle thread to the ready set. */ private static void createIdleThread() { Lib.assertTrue(idleThread == null); idleThread = new KThread( new Runnable() { public void run() { while (true) yield(); } }); idleThread.setName("idle"); Machine.autoGrader().setIdleThread(idleThread); idleThread.fork(); }
/** * 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; } }
/** * 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()); // FIXME Touhid :: Wake threads that have joined the currently running // thread currentThread.wakeJoinedThreads(); Machine.interrupt().disable(); Machine.autoGrader().finishingCurrentThread(); Lib.assertTrue(toBeDestroyed == null); toBeDestroyed = currentThread; currentThread.status = statusFinished; sleep(); }
/** * 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; // When this thread is finished, we need to reset the status of all // waited/blocked thread to ready state. while (!currentThread.waitedThreadList.isEmpty()) { KThread threadToRestore = currentThread.waitedThreadList.remove(0); threadToRestore.ready(); } sleep(); }
/** * 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(); }