1 /* Tests that the highest-priority thread waiting on a semaphore
2 is the first to wake up. */
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_sema_thread;
13 static struct semaphore sema;
16 test_priority_sema (void)
20 /* This test does not work with the MLFQS. */
21 ASSERT (!thread_mlfqs);
24 thread_set_priority (PRI_MIN);
25 for (i = 0; i < 10; i++)
27 int priority = PRI_DEFAULT - (i + 3) % 10 - 1;
29 snprintf (name, sizeof name, "priority %d", priority);
30 thread_create (name, priority, priority_sema_thread, NULL);
33 for (i = 0; i < 10; i++)
36 msg ("Back in main thread.");
41 priority_sema_thread (void *aux UNUSED)
44 msg ("Thread %s woke up.", thread_name ());