Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://927711]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2018-05-26 16:26 GMT
Find Nodes?
    Voting Booth?