Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) 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.

In reply to Re: 'better mousetrap': how to perform timed event by BrowserUk
in thread 'better mousetrap': how to perform timed event by snafu

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2021-06-13 15:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (57 votes). Check out past polls.

    Notices?