|more useful options|
Re: 'better mousetrap': how to perform timed eventby BrowserUk (Pope)
|on Apr 23, 2003 at 03:03 UTC||Need Help??|
Given the restriction on using threads which would be my preferred approach, I think that you could acheive a solution by avoiding the blocking read that is responsible for the indeterminate delays that can screw things up. You might do this by monitoring the length of the file in the while loop and only issuing a read when you are sure that there is enough data there to avoid the block. If you know your lines are alway 100 chars, wait till you have more than that before attempting to read a line. Alternatively, use sysread to get whatever is available into a buffer and extract the lines from there yourself.
If you store your events in a hash of arrays of events, keyed by the time when they are due to be enacted, and used Timer::HiRes or a 4-arg select statement with a delay of half your desired resolution to prevent the loop from running away with the processor, you are guarenteed to wake up at least once in each timer period and can then easily select those events due for enactment in the current time period. This shift of emphasis away from reading the file controlling the loop to using a timer should allow you to enact the events in a timely manner.
It's the approach I would try anyway, good luck.
Examine what is said, not who speaks.
1) When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong.
2) The only way of discovering the limits of the possible is to venture a little way past them into the impossible
3) Any sufficiently advanced technology is indistinguishable from magic.
Arthur C. Clarke.