Fix two bugs in the base Pintos code:
[pintos-anon] / src / tests / threads / priority-preempt.c
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
15 static thread_func simple_thread_func;
16
17 void
18 test_priority_preempt (void) 
19 {
20   /* This test does not work with the MLFQS. */
21   ASSERT (!thread_mlfqs);
22
23   /* Make sure our priority is the default. */
24   ASSERT (thread_get_priority () == PRI_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 
31 simple_thread_func (void *aux UNUSED) 
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 }