00001 /* Ensures that a high-priority thread really preempts. 00002 00003 Based on a test originally submitted for Stanford's CS 140 in 00004 winter 1999 by by Matt Franklin 00005 <startled@leland.stanford.edu>, Greg Hutchins 00006 <gmh@leland.stanford.edu>, Yu Ping Hu <yph@cs.stanford.edu>. 00007 Modified by arens. */ 00008 00009 #include <stdio.h> 00010 #include "tests/threads/tests.h" 00011 #include "threads/init.h" 00012 #include "threads/synch.h" 00013 #include "threads/thread.h" 00014 00015 static thread_func simple_thread_func; 00016 00017 void 00018 test_priority_preempt (void) 00019 { 00020 /* This test does not work with the MLFQS. */ 00021 ASSERT (!thread_mlfqs); 00022 00023 /* Make sure our priority is the default. */ 00024 ASSERT (thread_get_priority () == PRI_DEFAULT); 00025 00026 thread_create ("high-priority", PRI_DEFAULT + 1, simple_thread_func, NULL); 00027 msg ("The high-priority thread should have already completed."); 00028 } 00029 00030 static void 00031 simple_thread_func (void *aux UNUSED) 00032 { 00033 int i; 00034 00035 for (i = 0; i < 5; i++) 00036 { 00037 msg ("Thread %s iteration %d", thread_name (), i); 00038 thread_yield (); 00039 } 00040 msg ("Thread %s done!", thread_name ()); 00041 }