Actually you are right.
I didn't real explained myself.
I do want to terminate the threads childs and do some processing afterward (writing to a DB) , and then exit the child (fork) , and then exit the father.
I got some answers here - and it really really helped, so thank you for that.
I used the shared variable, and manaaged to kill all threads how I wanted.
the problem now is that , if I dont kill the thread - I just get a hang , and nothing happens . I just don't know how to signal the sleep that all threads ended succesfully (and I want to join them).
here is what I got so far :
$SIG{USR1} = sub {shutdown = 1;};
foreach my $functions_name (@func_arr){
#Start new thread
my $t = threads->create (sub{
&$functions_name(@parameters);
$SIG{KILL} = sub {
print "\ngot to thread killer\n\n";
threads->exit();
};
print "\ngot to end of thread\n\n";
#$shutdown = 1;
});
push(@threads,$t);
}
sleep until $shutdown;
if (my @remain = threads->list(threads::running)) {
foreach (@remain) {
if ($_ != $$){
$_->kill('KILL')->detach;
}
}
$shutdown = 0;
testProcess::prc_kill_handler();
}
print "All threads exited normally.";
my $index=0;
foreach my $thread (@threads) #wait for all threads untill the end
+and insert results to hash
{
$hash_results{$index}=$thread->join;
$index++;
}
return %hash_results;
Again ,this code actually works good when sending USR1 signal , but it doesn't when I'm not sending any signal , it just reaches to :
print "\ngot to end of thread\n\n";
and then nothing happens.
how can I handle that ?
thanks again guys ! sorry if I'm not so clear again...
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.