CS318 - Pintos
Pintos source browser for JHU CS318 course
priority-change.c
Go to the documentation of this file.
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 
11 
12 void
14 {
15  /* This test does not work with the 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.");
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.");
30  msg ("Thread 2 exiting.");
31 }
test_priority_change
void test_priority_change(void)
Definition: priority-change.c:13
NULL
#define NULL
Definition: stddef.h:4
UNUSED
#define UNUSED
GCC lets us add "attributes" to functions, function parameters, etc.
Definition: debug.h:7
init.h
ASSERT
#define ASSERT(CONDITION)
This is outside the header guard so that debug.h may be included multiple times with different settin...
Definition: debug.h:31
msg
void msg(const char *format,...)
Definition: lib.c:28
thread_mlfqs
bool thread_mlfqs
If false (default), use round-robin scheduler.
Definition: thread.c:60
thread_create
tid_t thread_create(const char *name, int priority, thread_func *function, void *aux)
Creates a new kernel thread named NAME with the given initial PRIORITY, which executes FUNCTION passi...
Definition: thread.c:166
thread_set_priority
void thread_set_priority(int new_priority)
Sets the current thread's priority to NEW_PRIORITY.
Definition: thread.c:336
tests.h
thread_func
void thread_func(void *aux)
Definition: thread.h:116
changing_thread
static thread_func changing_thread
Verifies that lowering a thread's priority so that it is no longer the highest-priority thread in the...
Definition: priority-change.c:10
thread.h
PRI_DEFAULT
#define PRI_DEFAULT
Default priority.
Definition: thread.h:24