1 /* The main thread acquires a lock. Then it creates a
2 higher-priority thread that blocks acquiring the lock, causing
3 it to donate their priorities to the main thread. The main
4 thread attempts to lower its priority, which should not take
5 effect until the donation is released. */
8 #include "tests/threads/tests.h"
9 #include "threads/init.h"
10 #include "threads/synch.h"
11 #include "threads/thread.h"
13 static thread_func acquire_thread_func;
16 test_priority_donate_lower (void)
20 /* This test does not work with the MLFQS. */
21 ASSERT (!enable_mlfqs);
23 /* Make sure our priority is the default. */
24 ASSERT (thread_get_priority () == PRI_DEFAULT);
28 thread_create ("acquire", PRI_DEFAULT + 10, acquire_thread_func, &lock);
29 msg ("Main thread should have priority %d. Actual priority: %d.",
30 PRI_DEFAULT + 10, thread_get_priority ());
32 msg ("Lowering base priority...");
33 thread_set_priority (PRI_DEFAULT - 10);
34 msg ("Main thread should have priority %d. Actual priority: %d.",
35 PRI_DEFAULT + 10, thread_get_priority ());
37 msg ("acquire must already have finished.");
38 msg ("Main thread should have priority %d. Actual priority: %d.",
39 PRI_DEFAULT - 10, thread_get_priority ());
43 acquire_thread_func (void *lock_)
45 struct lock *lock = lock_;
48 msg ("acquire: got the lock");
50 msg ("acquire: done");