+/* Checks that when the alarm clock wakes up threads, the
+ higher-priority threads run first. */
+
#include <stdio.h>
#include "tests/threads/tests.h"
#include "threads/init.h"
for (i = 0; i < 10; i++)
{
- int priority = (i + 5) % 10 + PRI_DEFAULT + 1;
+ int priority = PRI_DEFAULT - (i + 5) % 10 - 1;
char name[16];
snprintf (name, sizeof name, "priority %d", priority);
thread_create (name, priority, alarm_priority_thread, NULL);
}
- thread_set_priority (PRI_MAX);
+ thread_set_priority (PRI_MIN);
for (i = 0; i < 10; i++)
sema_down (&wait_sema);
alarm_priority_thread (void *aux UNUSED)
{
/* Busy-wait until the current time changes. */
- int64_t start_time;
+ int64_t start_time = timer_ticks ();
while (timer_elapsed (start_time) == 0)
continue;