CS318 - Pintos
Pintos source browser for JHU CS318 course
priority-preempt.c
Go to the documentation of this file.
1 /** Ensures that a high-priority thread really preempts.
2 
3  Based on a test originally submitted for Stanford's CS 140 in
4  winter 1999 by by Matt Franklin
5  <startled@leland.stanford.edu>, Greg Hutchins
6  <gmh@leland.stanford.edu>, Yu Ping Hu <yph@cs.stanford.edu>.
7  Modified by arens. */
8 
9 #include <stdio.h>
10 #include "tests/threads/tests.h"
11 #include "threads/init.h"
12 #include "threads/synch.h"
13 #include "threads/thread.h"
14 
16 
17 void
19 {
20  /* This test does not work with the MLFQS. */
22 
23  /* Make sure our priority is the default. */
25 
26  thread_create ("high-priority", PRI_DEFAULT + 1, simple_thread_func, NULL);
27  msg ("The high-priority thread should have already completed.");
28 }
29 
30 static void
32 {
33  int i;
34 
35  for (i = 0; i < 5; i++)
36  {
37  msg ("Thread %s iteration %d", thread_name (), i);
38  thread_yield ();
39  }
40  msg ("Thread %s done!", thread_name ());
41 }
NULL
#define NULL
Definition: stddef.h:4
UNUSED
#define UNUSED
GCC lets us add "attributes" to functions, function parameters, etc.
Definition: debug.h:7
thread_name
const char * thread_name(void)
Returns the name of the running thread.
Definition: thread.c:247
thread_get_priority
int thread_get_priority(void)
Returns the current thread's priority.
Definition: thread.c:343
init.h
simple_thread_func
static thread_func simple_thread_func
Ensures that a high-priority thread really preempts.
Definition: priority-preempt.c:15
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
test_priority_preempt
void test_priority_preempt(void)
Definition: priority-preempt.c:18
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
tests.h
thread_func
void thread_func(void *aux)
Definition: thread.h:116
thread.h
synch.h
thread_yield
void thread_yield(void)
Yields the CPU.
Definition: thread.c:302
PRI_DEFAULT
#define PRI_DEFAULT
Default priority.
Definition: thread.h:24