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.
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |