PKUOS - Pintos
Pintos source browser for PKU Operating System 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
17void
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
30static 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}
#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
#define UNUSED
GCC lets us add "attributes" to functions, function parameters, etc.
Definition: debug.h:7
void msg(const char *format,...)
Definition: lib.c:28
static thread_func simple_thread_func
Ensures that a high-priority thread really preempts.
void test_priority_preempt(void)
#define NULL
Definition: stddef.h:4
bool thread_mlfqs
If false (default), use round-robin scheduler.
Definition: thread.c:60
int thread_get_priority(void)
Returns the current thread's priority.
Definition: thread.c:343
const char * thread_name(void)
Returns the name of the running thread.
Definition: thread.c:247
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
void thread_yield(void)
Yields the CPU.
Definition: thread.c:302
#define PRI_DEFAULT
Default priority.
Definition: thread.h:24
void thread_func(void *aux)
Definition: thread.h:116