CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced: Re: [vivekchamp103] Kill the current thread and continue with main program: Edit Log



FishMonger
Veteran / Moderator

May 24, 2015, 10:14 AM


Views: 8374
Re: [vivekchamp103] Kill the current thread and continue with main program

Once you fix the compilation error, the script will work as expected, but I'd reduce the sleep value in the subroutine to no more than 15. I think the ideal sleep value is the same as the timeout.


Code
#!/perl 

use strict;
use warnings;
use threads;

my $timeout=10;
my $thr = threads->create(sub {
threads->yield();
local $SIG{'KILL'} = sub {
threads->exit();
};
sleep($timeout);
});


my $counter=0;
while (1){
if ($thr->is_running()){
if ($counter != $timeout){
$counter++;
sleep 1;
print "$counter, is running:\n";
}
else {
print "inside else\n";
$thr->kill('KILL');
}
}
else {
last;
}
}
print "print this first\n";
$thr->join();
print "print this last \n";



(This post was edited by FishMonger on May 24, 2015, 10:17 AM)


Edit Log:
Post edited by FishMonger (Veteran) on May 24, 2015, 10:17 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives