summaryrefslogtreecommitdiffstats
path: root/pintos-progos/tests/threads/priority-donate-lower.c
diff options
context:
space:
mode:
Diffstat (limited to 'pintos-progos/tests/threads/priority-donate-lower.c')
-rw-r--r--pintos-progos/tests/threads/priority-donate-lower.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/pintos-progos/tests/threads/priority-donate-lower.c b/pintos-progos/tests/threads/priority-donate-lower.c
new file mode 100644
index 0000000..4965d75
--- /dev/null
+++ b/pintos-progos/tests/threads/priority-donate-lower.c
@@ -0,0 +1,51 @@
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. */
6
7#include <stdio.h>
8#include "tests/threads/tests.h"
9#include "threads/init.h"
10#include "threads/synch.h"
11#include "threads/thread.h"
12
13static thread_func acquire_thread_func;
14
15void
16test_priority_donate_lower (void)
17{
18 struct lock lock;
19
20 /* This test does not work with the MLFQS. */
21 ASSERT (!thread_mlfqs);
22
23 /* Make sure our priority is the default. */
24 ASSERT (thread_get_priority () == PRI_DEFAULT);
25
26 lock_init (&lock);
27 lock_acquire (&lock);
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 ());
31
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 ());
36 lock_release (&lock);
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 ());
40}
41
42static void
43acquire_thread_func (void *lock_)
44{
45 struct lock *lock = lock_;
46
47 lock_acquire (lock);
48 msg ("acquire: got the lock");
49 lock_release (lock);
50 msg ("acquire: done");
51}