Class Timer

  extended by nachos.machine.Timer

public final class Timer
extends Object

A hardware timer generates a CPU timer interrupt approximately every 500 clock ticks. This means that it can be used for implementing time-slicing, or for having a thread go to sleep for a specific period of time. The Timer class emulates a hardware timer by scheduling a timer interrupt to occur every time approximately 500 clock ticks pass. There is a small degree of randomness here, so interrupts do not occur exactly every 500 ticks.

Constructor Summary
Timer(Privilege privilege)
          Allocate a new timer.
Method Summary
 long getTime()
          Get the current time.
 void setInterruptHandler(Runnable handler)
          Set the callback to use as a timer interrupt handler.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail


public Timer(Privilege privilege)
Allocate a new timer.

privilege - encapsulates privileged access to the Nachos machine.
Method Detail


public void setInterruptHandler(Runnable handler)
Set the callback to use as a timer interrupt handler. The timer interrupt handler will be called approximately every 500 clock ticks.

handler - the timer interrupt handler.


public long getTime()
Get the current time.

the number of clock ticks since Nachos started.