- #1
prashantgolu
- 50
- 0
Write a monitor that implements an alarm clock that enables a calling program to delay itself for a specifed number of time units (ticks). You may assume the existence of a real hardware clock that invokes a procedure "tick" in your monitor at regular intervals.
the solution is :
monitor AlarmClock
int now=0;
condition wakeup;
wakeme(int n){
int alarm;
alarm = now + n;
while (now < alarm) wakeup.wait(alarm);
wakeup.signal;
}
tick() {
now = now + 1;
wakeup.signal;
}
Why Wakeup.signal in wake me function...i think the last wakeup signal in tick() will wakeup the process...
the solution is :
monitor AlarmClock
int now=0;
condition wakeup;
wakeme(int n){
int alarm;
alarm = now + n;
while (now < alarm) wakeup.wait(alarm);
wakeup.signal;
}
tick() {
now = now + 1;
wakeup.signal;
}
Why Wakeup.signal in wake me function...i think the last wakeup signal in tick() will wakeup the process...