1 /* The main thread acquires locks A and B, then it creates three
2 higher-priority threads. The first two of these threads block
3 acquiring one of the locks and thus donate their priority to
4 the main thread. The main thread releases the locks in turn
5 and relinquishes its donated priorities, allowing the third thread
8 In this test, the main thread releases the locks in a different
9 order compared to priority-donate-multiple.c.
11 Written by Godmar Back <gback@cs.vt.edu>.
12 Based on a test originally submitted for Stanford's CS 140 in
13 winter 1999 by Matt Franklin <startled@leland.stanford.edu>,
14 Greg Hutchins <gmh@leland.stanford.edu>, Yu Ping Hu
15 <yph@cs.stanford.edu>. Modified by arens. */
18 #include "tests/threads/tests.h"
19 #include "threads/init.h"
20 #include "threads/synch.h"
21 #include "threads/thread.h"
23 static thread_func a_thread_func;
24 static thread_func b_thread_func;
25 static thread_func c_thread_func;
28 test_priority_donate_multiple2 (void)
32 /* This test does not work with the MLFQS. */
33 ASSERT (!enable_mlfqs);
35 /* Make sure our priority is the default. */
36 ASSERT (thread_get_priority () == PRI_DEFAULT);
44 thread_create ("a", PRI_DEFAULT + 3, a_thread_func, &a);
45 msg ("Main thread should have priority %d. Actual priority: %d.",
46 PRI_DEFAULT + 3, thread_get_priority ());
48 thread_create ("c", PRI_DEFAULT + 1, c_thread_func, NULL);
50 thread_create ("b", PRI_DEFAULT + 5, b_thread_func, &b);
51 msg ("Main thread should have priority %d. Actual priority: %d.",
52 PRI_DEFAULT + 5, thread_get_priority ());
55 msg ("Main thread should have priority %d. Actual priority: %d.",
56 PRI_DEFAULT + 5, thread_get_priority ());
59 msg ("Threads b, a, c should have just finished, in that order.");
60 msg ("Main thread should have priority %d. Actual priority: %d.",
61 PRI_DEFAULT, thread_get_priority ());
65 a_thread_func (void *lock_)
67 struct lock *lock = lock_;
70 msg ("Thread a acquired lock a.");
72 msg ("Thread a finished.");
76 b_thread_func (void *lock_)
78 struct lock *lock = lock_;
81 msg ("Thread b acquired lock b.");
83 msg ("Thread b finished.");
87 c_thread_func (void *a_ UNUSED)
89 msg ("Thread c finished.");