Program Semaphores: Write Monitor Alarm Clock Delay Time Units

  • Thread starter Thread starter prashantgolu
  • Start date Start date
  • Tags Tags
    Program
Click For Summary

Discussion Overview

The discussion centers around the implementation of a monitor for an alarm clock that allows a program to delay execution for a specified number of time units (ticks). Participants explore the design and functionality of the monitor, addressing potential issues and improvements in the proposed solution.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant questions the necessity of the last wakeup.signal in the wakeme function, suggesting that the tick function's wakeup.signal should suffice to wake the process.
  • Another participant raises the concern that if multiple processes can be woken up at the same tick, it may complicate the signaling mechanism.
  • A participant critiques the original solution's syntax, suggesting it appears to be in C but contains significant errors, and proposes a need for a message handling system with two threads: one for waiting and another for processing ticks.
  • Another participant points out that the original solution does not account for wrap around in the time units and suggests using a separate signal for the tick function to address this issue.

Areas of Agreement / Disagreement

Participants express differing views on the implementation details, particularly regarding the signaling mechanism and the handling of time wrap around. No consensus is reached on the best approach, indicating ongoing debate and exploration of the topic.

Contextual Notes

Limitations include unresolved questions about the syntax and structure of the proposed code, as well as assumptions regarding the behavior of the hardware clock and the handling of concurrent processes.

Who May Find This Useful

Readers interested in concurrent programming, monitor design, and thread management in programming languages, particularly those working with timing mechanisms and synchronization issues.

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;
}
 

Similar threads

  • · Replies 13 ·
Replies
13
Views
4K