Program Semaphores: Write Monitor Alarm Clock Delay Time Units

  • Thread starter Thread starter prashantgolu
  • Start date Start date
  • Tags Tags
    Program
AI Thread Summary
The discussion centers on creating a monitor for an alarm clock that allows a calling program to delay itself for a specified number of time units, using a hardware clock that triggers a "tick" procedure. The initial solution provided uses a structure with an integer to track the current time and a condition variable for managing wake-up signals. A key point raised is the necessity of the wakeup.signal in the wakeme function, suggesting that the final signal in the tick function might not suffice if multiple processes are waiting to be awakened at the same tick. Further suggestions include implementing a simple message handling system with two threads: one for waiting and another for managing ticks. The original solution is critiqued for not handling time wrap-around and for potential syntax issues, with a revised version proposed that introduces a separate condition for tick signals to improve functionality and clarity.
prashantgolu
Messages
50
Reaction score
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...
 
Technology news on Phys.org
if there is another process that can be woke up at the same tick
 
What library are you using and what language is that? It looks like C, but has some glaring syntax problems.

Sounds like you want a simple message handling system. You will need two threads to properly demonstrate it: one that's doing the waiting, and the one that's looping through ticks until it can trigger the callback.
 
The solution doesn't handle wrap around, and tick should use a separate signal. An example that does:

int now=0;
condition wakeup;
condition ticksleep;

wakeme(int n){
int alarm;
int then;
then = now;
while((now - then) < n) wakeup.wait(ticksleep);
wakeup.signal;
}

tick() {
now = now + 1;
ticksleep.signal;
}
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
hi; i purchased 3 of these, AZDelivery 3 x AZ-MEGA2560-Board Bundle with Prototype Shield and each is reporting the error message below. I have triple checked every aspect of the set up and all seems in order, cable devices port, board reburn bootloader et al . I have substituted an arduino uno and it works fine; could you help please Thanks Martyn 'avrdude: ser_open(): can't set com-state for "\\.\COM3"avrdude: ser_drain(): read error: The handle is invalid.avrdude: ser_send(): write...

Similar threads

Replies
13
Views
3K
Back
Top