
Alarm Class waitUntil()
By: a guest on
May 1st, 2012 | syntax:
Java | size: 1.62 KB | hits: 22 | expires: Never
/*
* Tests the functionality of the alarm class.
* Because "nachos will not function correctly with more than one alarm",
* and the only alarm is instantiated in the threadKernel class, the
* alarm is passed here from the threadKernel's selfTest.
*/
public static void selfTest(final Alarm alarm) {
System.out.format("\nTesting waitUntil in the Alarm class...\n");
KThread alarmThread1 = new KThread(new Runnable() {
public void run(){
System.out.format("Thread 1 waiting, 500000 ticks...\n");
alarm.waitUntil(500000);
System.out.format("\nThread 1 done waiting.\n\n");
}
});
KThread alarmThread2 = new KThread(new Runnable() {
public void run(){
System.out.format("Thread 2 waiting, 1000000 ticks...\n");
alarm.waitUntil(1000000);
System.out.format("Thread 2 done waiting.\n\n");
}
});
KThread alarmThread3 = new KThread(new Runnable() {
public void run(){
System.out.format("Thread 3 waiting, 3000000 ticks...\n");
alarm.waitUntil(3000000);
System.out.format("Thread 3 done waiting.\n\n");
}
});
KThread alarmThread4 = new KThread(new Runnable() {
public void run(){
System.out.format("Thread 4 waiting, 5000000 ticks...\n");
alarm.waitUntil(5000000);
System.out.format("Thread 4 done waiting.\n\n");
}
});
alarmThread1.fork();
alarmThread2.fork();
alarmThread3.fork();
alarmThread4.fork();
// have to join or machine halts prematurely
alarmThread4.join();
}