Use runtime options instead of conditional compilation for MLFQS,
[pintos-anon] / src / threads / thread.c
index ae92e1d646dc50d50ce02d26747ca12a8bd82236..02f3c7b62bb1f949a3a739be3bad3367591fb33c 100644 (file)
@@ -274,17 +274,6 @@ thread_yield (void)
   intr_set_level (old_level);
 }
 
-/* Waits for the thread with the specified TID to terminate.  If
-   TID has already terminated or TID does not refer to an
-   immediate child of the current thread, returns immediately.
-
-   This function will be implemented in problem 1-2.  For now, it
-   does nothing. */
-void
-thread_join (tid_t child_tid UNUSED) 
-{
-}
-
 /* Sets the current thread's priority to NEW_PRIORITY. */
 void
 thread_set_priority (int new_priority) 
@@ -310,11 +299,19 @@ idle (void *aux UNUSED)
       /* Let someone else run. */
       intr_disable ();
       thread_block ();
-      intr_enable ();
 
-      /* Use CPU `hlt' instruction to wait for interrupt.
-         See [IA32-v2a] "HLT" and [IA32-v3] 7.7. */
-      asm ("hlt");
+      /* Re-enable interrupts and wait for the next one.
+
+         The `sti' instruction disables interrupts until the
+         completion of the next instruction, so these two
+         instructions are executed atomically.  This atomicity is
+         important; otherwise, an interrupt could be handled
+         between re-enabling interrupts and waiting for the next
+         one to occur, wasting as much as one clock tick worth of
+         time.
+
+         See [IA32-v2a] "HLT", [IA32-v2b] "STI", and [IA32-v3] 7.7. */
+      asm ("sti; hlt");
     }
 }