CO631 Anonymous Questions and Answers Keyword Index |
This page provides a keyword index to questions and answers. Clicking on a keyword will take you to a page containing all questions and answers for that keyword, grouped by year.
To submit a question, use the anonymous questions page. You may find the keyword index and/or top-level index useful for locating past questions and answers.
Keyword reference for timers
2004 |
Is this the correct piece of code for waiting a random time ?
SEQ seed := seed + id i, seed := random(num, seed) tim ? t tim ? AFTER t PLUS i
More or less, yes. Make sure you initialise "seed" appropriately though -- the code above initialises it based on itself (if undefined, it'll stay undefined). As covered in the seminars, a quick way to get an initial seed value is:
tim ? seed seed := (seed >> 2) + 1 -- maybe also add in the `id'
Remember also that your seed should be explicitly initialised like this just once -- before loop entry. Within the loop, cycling through the philosopher's life, the seed value gets updated as you use the random function. The sequence of seed values takes you through the "random" numbers. If you re-initialise the seed every time round the loop, the computed randomness will be lost.
Hi, what is the best way to to wait 1 second within a loop ? (Required for q5)
See the answer to Question 80 (2000).
Keywords: timers
2002 |
Could you please explain a little more how you would go about implementing the random time delay? I have read through the previous questions on it but I'm still a little lost. Is the time delay between philosophers doing different actions or in the display process?
It's in the philosopher processes - not the display.
The question says:
Thinking and eating by the philosophers should be modelled by random (but finite!) delays
In the "philosopher" process there are two folds:
<!--{{{ think--> SKIP <!--}}}-->
and:
<!--{{{ eat--> SKIP <!--}}}-->
You should replace the SKIPs by random delays.
Keywords: q7 , random , timers
2000 |
Thinking and eating by the philosphers should be modelled by random (but finite!) delays.
Assuming we have obtained a random number, what's the best way to implement the delay ... i.e. pause execution for a random time? Is there a wait(time) function or such like?
See slide 4-40 and sections 3.4/3.5 of the "OCCAM2 CHECKLIST" paper. Spelling it out:
TIMER tim: INT t: SEQ tim ? t tim ? AFTER t PLUS waiting.time
Referrers: Question 59 (2004)
When it comes to TIMERs, how is the time counted? Does the internal enviornment time in nanoseconds or microseconds? Also does it go like this:
1000000 nanoseconds = 1 second 10000 microseconds = 1 second
occam TIMERs, in KRoC Solaris/Linux systems, increment every microsecond. And, for information:
1000000000 nanoseconds = 1 second 1000000 microseconds = 1 second
Keywords: timers
Last modified Mon May 15 17:39:48 2006
|