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 acquire1_thread_func;
00019 static thread_func acquire2_thread_func;
00020
00021 void
00022 test_priority_donate_one (void)
00023 {
00024 struct lock lock;
00025
00026
00027 ASSERT (!thread_mlfqs);
00028
00029
00030 ASSERT (thread_get_priority () == PRI_DEFAULT);
00031
00032 lock_init (&lock);
00033 lock_acquire (&lock);
00034 thread_create ("acquire1", PRI_DEFAULT + 1, acquire1_thread_func, &lock);
00035 msg ("This thread should have priority %d. Actual priority: %d.",
00036 PRI_DEFAULT + 1, thread_get_priority ());
00037 thread_create ("acquire2", PRI_DEFAULT + 2, acquire2_thread_func, &lock);
00038 msg ("This thread should have priority %d. Actual priority: %d.",
00039 PRI_DEFAULT + 2, thread_get_priority ());
00040 lock_release (&lock);
00041 msg ("acquire2, acquire1 must already have finished, in that order.");
00042 msg ("This should be the last line before finishing this test.");
00043 }
00044
00045 static void
00046 acquire1_thread_func (void *lock_)
00047 {
00048 struct lock *lock = lock_;
00049
00050 lock_acquire (lock);
00051 msg ("acquire1: got the lock");
00052 lock_release (lock);
00053 msg ("acquire1: done");
00054 }
00055
00056 static void
00057 acquire2_thread_func (void *lock_)
00058 {
00059 struct lock *lock = lock_;
00060
00061 lock_acquire (lock);
00062 msg ("acquire2: got the lock");
00063 lock_release (lock);
00064 msg ("acquire2: done");
00065 }