00001 /* The main thread acquires a lock. Then it creates a 00002 higher-priority thread that blocks acquiring the lock, causing 00003 it to donate their priorities to the main thread. The main 00004 thread attempts to lower its priority, which should not take 00005 effect until the donation is released. */ 00006 00007 #include <stdio.h> 00008 #include "tests/threads/tests.h" 00009 #include "threads/init.h" 00010 #include "threads/synch.h" 00011 #include "threads/thread.h" 00012 00013 static thread_func acquire_thread_func; 00014 00015 void 00016 test_priority_donate_lower (void) 00017 { 00018 struct lock lock; 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 lock_init (&lock); 00027 lock_acquire (&lock); 00028 thread_create ("acquire", PRI_DEFAULT + 10, acquire_thread_func, &lock); 00029 msg ("Main thread should have priority %d. Actual priority: %d.", 00030 PRI_DEFAULT + 10, thread_get_priority ()); 00031 00032 msg ("Lowering base priority..."); 00033 thread_set_priority (PRI_DEFAULT - 10); 00034 msg ("Main thread should have priority %d. Actual priority: %d.", 00035 PRI_DEFAULT + 10, thread_get_priority ()); 00036 lock_release (&lock); 00037 msg ("acquire must already have finished."); 00038 msg ("Main thread should have priority %d. Actual priority: %d.", 00039 PRI_DEFAULT - 10, thread_get_priority ()); 00040 } 00041 00042 static void 00043 acquire_thread_func (void *lock_) 00044 { 00045 struct lock *lock = lock_; 00046 00047 lock_acquire (lock); 00048 msg ("acquire: got the lock"); 00049 lock_release (lock); 00050 msg ("acquire: done"); 00051 }