Comment fixes.
[pintos-anon] / src / tests / threads / priority-donate-multiple.c
1 /* Based on a test originally submitted for Stanford's CS 140 in
2    winter 1999 by Matt Franklin <startled@leland.stanford.edu>,
3    Greg Hutchins <gmh@leland.stanford.edu>, Yu Ping Hu
4    <yph@cs.stanford.edu>.  Modified by arens. */
5
6 #include <stdio.h>
7 #include "tests/threads/tests.h"
8 #include "threads/init.h"
9 #include "threads/synch.h"
10 #include "threads/thread.h"
11
12 static thread_func a_thread_func;
13 static thread_func b_thread_func;
14
15 void
16 test_priority_donate_multiple (void) 
17 {
18   struct lock a, b;
19
20   /* This test does not work with the MLFQS. */
21   ASSERT (!enable_mlfqs);
22
23   /* Make sure our priority is the default. */
24   ASSERT (thread_get_priority () == PRI_DEFAULT);
25
26   lock_init (&a);
27   lock_init (&b);
28
29   lock_acquire (&a);
30   lock_acquire (&b);
31
32   thread_create ("a", PRI_DEFAULT - 1, a_thread_func, &a);
33   msg ("Main thread should have priority %d.  Actual priority: %d.",
34        PRI_DEFAULT - 1, thread_get_priority ());
35
36   thread_create ("b", PRI_DEFAULT - 2, b_thread_func, &b);
37   msg ("Main thread should have priority %d.  Actual priority: %d.",
38        PRI_DEFAULT - 2, thread_get_priority ());
39
40   lock_release (&b);
41   msg ("Thread b should have just finished.");
42   msg ("Main thread should have priority %d.  Actual priority: %d.",
43        PRI_DEFAULT - 1, thread_get_priority ());
44
45   lock_release (&a);
46   msg ("Thread a should have just finished.");
47   msg ("Main thread should have priority %d.  Actual priority: %d.",
48        PRI_DEFAULT, thread_get_priority ());
49 }
50
51 static void
52 a_thread_func (void *lock_) 
53 {
54   struct lock *lock = lock_;
55
56   lock_acquire (lock);
57   msg ("Thread a acquired lock a.");
58   lock_release (lock);
59   msg ("Thread a finished.");
60 }
61
62 static void
63 b_thread_func (void *lock_) 
64 {
65   struct lock *lock = lock_;
66
67   lock_acquire (lock);
68   msg ("Thread b acquired lock b.");
69   lock_release (lock);
70   msg ("Thread b finished.");
71 }