Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Try it this way (untested):

use threads; use Thread::Queue; sub processEvents { my $Q = shift; while( my $event = $Q->dequeue ) { ## Process events } } my $Q = new Thread::Queue; my $thread = threads->create( \&processEvents, $Q ); $inotify->watch($watchpoint,IN_ALL_EVENTS); while ($keepOnWatching) { $Q->enqueue( $inotify->read; ) }

All the threading overhead is up-front, leaving the only processing in the 'event loop', pushing the returned values onto shared memory, which is barely slower than assigning them to your array.

If you find that the events are arriving faster than the thread can process them--and if you have multiple cores--start a second, third, fourth thread.

If this were Win32, I'd boost the priority of the main thread to real-time to ensure that it was favoured by the schedular in the event that both it and one of the processing threads became eligable to run at the same time. But I don't know how to do that on *nix.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re: How to wait for events, and not lose any, while processing them ? by BrowserUk
in thread How to wait for events, and not lose any, while processing them ? by Eyck

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 How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-03-28 17:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found