1 /* Tests that cond_signal() wakes up the highest-priority thread
2 waiting in cond_wait(). */
5 #include "tests/threads/tests.h"
6 #include "threads/init.h"
7 #include "threads/malloc.h"
8 #include "threads/synch.h"
9 #include "threads/thread.h"
10 #include "devices/timer.h"
12 static thread_func priority_condvar_thread;
13 static struct lock lock;
14 static struct condition condition;
17 test_priority_condvar (void)
21 /* This test does not work with the MLFQS. */
22 ASSERT (!enable_mlfqs);
25 cond_init (&condition);
27 thread_set_priority (PRI_MIN);
28 for (i = 0; i < 10; i++)
30 int priority = PRI_DEFAULT - (i + 7) % 10 - 1;
32 snprintf (name, sizeof name, "priority %d", priority);
33 thread_create (name, priority, priority_condvar_thread, NULL);
36 for (i = 0; i < 10; i++)
40 cond_signal (&condition, &lock);
46 priority_condvar_thread (void *aux UNUSED)
48 msg ("Thread %s starting.", thread_name ());
50 cond_wait (&condition, &lock);
51 msg ("Thread %s woke up.", thread_name ());