1e2a2685872735d7bc02414ac5ed8e0114e2dbc6
[pintos-anon] / grading / threads / priority-preempt.c
1 /* Problem 1-3: Priority Scheduling tests.
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 #ifdef MLFQS
10 #error This test not applicable with MLFQS enabled.
11 #endif
12
13 #include "threads/test.h"
14 #include <stdio.h>
15 #include "threads/synch.h"
16 #include "threads/thread.h"
17
18 static void test_preempt (void);
19
20 void
21 test (void) 
22 {
23   /* Make sure our priority is the default. */
24   ASSERT (thread_get_priority () == PRI_DEFAULT);
25
26   test_preempt ();
27 }
28 \f
29 static thread_func simple_thread_func;
30
31 static void
32 test_preempt (void) 
33 {
34   printf ("\n"
35           "Testing priority preemption.\n");
36   thread_create ("high-priority", PRI_DEFAULT + 1, simple_thread_func, NULL);
37   printf ("The high-priority thread should have already completed.\n"
38           "Priority preemption test done.\n");
39 }
40
41 static void 
42 simple_thread_func (void *aux UNUSED) 
43 {
44   int i;
45   
46   for (i = 0; i < 5; i++) 
47     {
48       printf ("Thread %s iteration %d\n", thread_name (), i);
49       thread_yield ();
50     }
51   printf ("Thread %s done!\n", thread_name ());
52 }