Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Waking threads that do periodic checks

by BrowserUk (Pope)
on Sep 25, 2011 at 06:17 UTC ( #927711=note: print w/ replies, xml ) Need Help??


in reply to Waking threads that do periodic checks

This is easy to do, though I agree there may well be better ways of solving the real problem:

#! perl -slw use strict; use threads; use threads::shared; my $quit :shared = 0; $SIG{INT} = sub { print 'SIGINT'; $quit = 1; }; async { while( not $quit ) { my $wakeup = time() + 60 * 60; print( $quit ), sleep 1 while not $quit and time() < $wakeup; ## Do the hourly task; } }->detach; sleep 1 while not $quit; __END__ c:\test>junk60 0 0 SIGINT

The cpu cost of waking once per second is nominal.


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.


Comment on Re: Waking threads that do periodic checks
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://927711]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (8)
As of 2014-12-28 06:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (178 votes), past polls