00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <stdio.h>
00018 #include "tests/threads/tests.h"
00019 #include "threads/init.h"
00020 #include "threads/synch.h"
00021 #include "threads/thread.h"
00022
00023 static thread_func a_thread_func;
00024 static thread_func b_thread_func;
00025 static thread_func c_thread_func;
00026
00027 void
00028 test_priority_donate_multiple2 (void)
00029 {
00030 struct lock a, b;
00031
00032
00033 ASSERT (!thread_mlfqs);
00034
00035
00036 ASSERT (thread_get_priority () == PRI_DEFAULT);
00037
00038 lock_init (&a);
00039 lock_init (&b);
00040
00041 lock_acquire (&a);
00042 lock_acquire (&b);
00043
00044 thread_create ("a", PRI_DEFAULT + 3, a_thread_func, &a);
00045 msg ("Main thread should have priority %d. Actual priority: %d.",
00046 PRI_DEFAULT + 3, thread_get_priority ());
00047
00048 thread_create ("c", PRI_DEFAULT + 1, c_thread_func, NULL);
00049
00050 thread_create ("b", PRI_DEFAULT + 5, b_thread_func, &b);
00051 msg ("Main thread should have priority %d. Actual priority: %d.",
00052 PRI_DEFAULT + 5, thread_get_priority ());
00053
00054 lock_release (&a);
00055 msg ("Main thread should have priority %d. Actual priority: %d.",
00056 PRI_DEFAULT + 5, thread_get_priority ());
00057
00058 lock_release (&b);
00059 msg ("Threads b, a, c should have just finished, in that order.");
00060 msg ("Main thread should have priority %d. Actual priority: %d.",
00061 PRI_DEFAULT, thread_get_priority ());
00062 }
00063
00064 static void
00065 a_thread_func (void *lock_)
00066 {
00067 struct lock *lock = lock_;
00068
00069 lock_acquire (lock);
00070 msg ("Thread a acquired lock a.");
00071 lock_release (lock);
00072 msg ("Thread a finished.");
00073 }
00074
00075 static void
00076 b_thread_func (void *lock_)
00077 {
00078 struct lock *lock = lock_;
00079
00080 lock_acquire (lock);
00081 msg ("Thread b acquired lock b.");
00082 lock_release (lock);
00083 msg ("Thread b finished.");
00084 }
00085
00086 static void
00087 c_thread_func (void *a_ UNUSED)
00088 {
00089 msg ("Thread c finished.");
00090 }