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: Kill the current thread and continue with main program: Edit Log



vivekchamp103
New User

May 23, 2015, 7:31 PM


Views: 8484
Kill the current thread and continue with main program

Hi,
I am trying to write a perl script, where it should perform some task using thread and after some time (timeout) if thread is not done with the task, it should get killed and continue with main program.
my sample program is here:
==================

Code
#!perl 
use threads;
my $thr = threads->create(sub {
threads->yield();

$SIG{'KILL'} = sub {
threads->exit();
};
sleep(25);

});
my $timeout=10;
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";
$threads->kill('KILL');
}
}
else {
last;
}
}
print "print this first\n";
$thr->join();
print "print this last \n";

===================
What I am expecting here is after threads killed, program should print "print this last".


(This post was edited by FishMonger on May 24, 2015, 8:54 AM)


Edit Log:
Post edited by FishMonger (Veteran) on May 24, 2015, 8:54 AM: Added code tags


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

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