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