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

Re: Waking threads that do periodic checks

by Khen1950fx (Canon)
on Sep 26, 2011 at 04:29 UTC ( #927788=note: print w/ replies, xml ) Need Help??


in reply to Waking threads that do periodic checks

It took some experimenting to find something that consistently worked as expected. This is what worked for me:

#!/usr/bin/perl use strict; use warnings; use threads; use Thread::Suspend; $|=1; my $TERM = 0; $SIG{'INT'} = $SIG{'TERM'} = sub { $TERM = 1; }; print "To terminate program, hit ctrl-^C\n"; sub start_thread { my @args = @_; print(join(' ', @args,)); } my $thr = threads->create(\&start_thread); $thr->join(); $thr->suspend(); $thr->yield(); sleep (1) until ($TERM); print ("\e[2K\e[?25h\n"); #to restore proper cursor behavior


Comment on Re: Waking threads that do periodic checks
Download Code
Re^2: Waking threads that do periodic checks
by BrowserUk (Pope) on Sep 26, 2011 at 04:57 UTC

    What do you think is the point of this code?:

    $thr->suspend(); $thr->yield();

    Given that it is proceed by: $thr->join(); which means that the thread no longer exists by the time the above two lines are executed. In addition, the ->yield() method of the threads module isn't exported by default, and you do not import it.

    Your code is exactly equivalent to:

    #!/usr/bin/perl use strict; use warnings; $|=1; my $TERM = 0; $SIG{'INT'} = $SIG{'TERM'} = sub { $TERM = 1; }; print "To terminate program, hit ctrl-^C\n"; print( join(' ', ()) ); sleep (1) until ($TERM);

    In other words it does exactly nothing useful and is in no way an answer to the OPs question.


    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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2015-07-02 08:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (31 votes), past polls