00001
00002
00003
00004 #include <stdio.h>
00005 #include "tests/threads/tests.h"
00006 #include "threads/init.h"
00007 #include "threads/malloc.h"
00008 #include "threads/synch.h"
00009 #include "threads/thread.h"
00010 #include "devices/timer.h"
00011
00012 static thread_func priority_condvar_thread;
00013 static struct lock lock;
00014 static struct condition condition;
00015
00016 void
00017 test_priority_condvar (void)
00018 {
00019 int i;
00020
00021
00022 ASSERT (!thread_mlfqs);
00023
00024 lock_init (&lock);
00025 cond_init (&condition);
00026
00027 thread_set_priority (PRI_MIN);
00028 for (i = 0; i < 10; i++)
00029 {
00030 int priority = PRI_DEFAULT - (i + 7) % 10 - 1;
00031 char name[16];
00032 snprintf (name, sizeof name, "priority %d", priority);
00033 thread_create (name, priority, priority_condvar_thread, NULL);
00034 }
00035
00036 for (i = 0; i < 10; i++)
00037 {
00038 lock_acquire (&lock);
00039 msg ("Signaling...");
00040 cond_signal (&condition, &lock);
00041 lock_release (&lock);
00042 }
00043 }
00044
00045 static void
00046 priority_condvar_thread (void *aux UNUSED)
00047 {
00048 msg ("Thread %s starting.", thread_name ());
00049 lock_acquire (&lock);
00050 cond_wait (&condition, &lock);
00051 msg ("Thread %s woke up.", thread_name ());
00052 lock_release (&lock);
00053 }