summaryrefslogtreecommitdiffstats
path: root/pintos-progos/tests/threads/priority-change.c
diff options
context:
space:
mode:
Diffstat (limited to 'pintos-progos/tests/threads/priority-change.c')
-rw-r--r--pintos-progos/tests/threads/priority-change.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/pintos-progos/tests/threads/priority-change.c b/pintos-progos/tests/threads/priority-change.c
new file mode 100644
index 0000000..810b05a
--- /dev/null
+++ b/pintos-progos/tests/threads/priority-change.c
@@ -0,0 +1,31 @@
1/* Verifies that lowering a thread's priority so that it is no
2 longer the highest-priority thread in the system causes it to
3 yield immediately. */
4
5#include <stdio.h>
6#include "tests/threads/tests.h"
7#include "threads/init.h"
8#include "threads/thread.h"
9
10static thread_func changing_thread;
11
12void
13test_priority_change (void)
14{
15 /* This test does not work with the MLFQS. */
16 ASSERT (!thread_mlfqs);
17
18 msg ("Creating a high-priority thread 2.");
19 thread_create ("thread 2", PRI_DEFAULT + 1, changing_thread, NULL);
20 msg ("Thread 2 should have just lowered its priority.");
21 thread_set_priority (PRI_DEFAULT - 2);
22 msg ("Thread 2 should have just exited.");
23}
24
25static void
26changing_thread (void *aux UNUSED)
27{
28 msg ("Thread 2 now lowering priority.");
29 thread_set_priority (PRI_DEFAULT - 1);
30 msg ("Thread 2 exiting.");
31}