diff options
| author | Felipe Boeira <felipe.boeira@liu.se> | 2019-01-08 18:39:03 +0100 |
|---|---|---|
| committer | Felipe Boeira <felipe.boeira@liu.se> | 2019-01-08 18:39:03 +0100 |
| commit | d4522b8e9854178473adcea0fbb84f23f6e744bd (patch) | |
| tree | fbcf620617c5023154eba3f965b3a982daa64a47 /src/tests/threads/priority-donate-lower.c | |
| download | pintos-d4522b8e9854178473adcea0fbb84f23f6e744bd.tar.gz | |
Initial commit
Diffstat (limited to 'src/tests/threads/priority-donate-lower.c')
| -rw-r--r-- | src/tests/threads/priority-donate-lower.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/tests/threads/priority-donate-lower.c b/src/tests/threads/priority-donate-lower.c new file mode 100644 index 0000000..4965d75 --- /dev/null +++ b/src/tests/threads/priority-donate-lower.c @@ -0,0 +1,51 @@ +/* The main thread acquires a lock. Then it creates a + higher-priority thread that blocks acquiring the lock, causing + it to donate their priorities to the main thread. The main + thread attempts to lower its priority, which should not take + effect until the donation is released. */ + +#include <stdio.h> +#include "tests/threads/tests.h" +#include "threads/init.h" +#include "threads/synch.h" +#include "threads/thread.h" + +static thread_func acquire_thread_func; + +void +test_priority_donate_lower (void) +{ + struct lock lock; + + /* This test does not work with the MLFQS. */ + ASSERT (!thread_mlfqs); + + /* Make sure our priority is the default. */ + ASSERT (thread_get_priority () == PRI_DEFAULT); + + lock_init (&lock); + lock_acquire (&lock); + thread_create ("acquire", PRI_DEFAULT + 10, acquire_thread_func, &lock); + msg ("Main thread should have priority %d. Actual priority: %d.", + PRI_DEFAULT + 10, thread_get_priority ()); + + msg ("Lowering base priority..."); + thread_set_priority (PRI_DEFAULT - 10); + msg ("Main thread should have priority %d. Actual priority: %d.", + PRI_DEFAULT + 10, thread_get_priority ()); + lock_release (&lock); + msg ("acquire must already have finished."); + msg ("Main thread should have priority %d. Actual priority: %d.", + PRI_DEFAULT - 10, thread_get_priority ()); +} + +static void +acquire_thread_func (void *lock_) +{ + struct lock *lock = lock_; + + lock_acquire (lock); + msg ("acquire: got the lock"); + lock_release (lock); + msg ("acquire: done"); +} |
