bb462d462d85fe02c1a4ca22a132883ec881c0b4
[pintos-anon] / src / tests / threads / priority-change.c
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
10 static thread_func changing_thread;
11
12 void
13 test_priority_change (void) 
14 {
15   /* This test does not work with the MLFQS. */
16   ASSERT (!enable_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
25 static void
26 changing_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 }