@BrowserUK - I am using the latest version of perl (why would anyone use anything less?)
The only reason I "store them" is to ensure it is a fresh thread everytime. Using my $thr -> will eventually crash.
The script is designed to do one thing. Process the list of tasks and just keep on going. Tasks (detached threads) may take a second and they may take an hour.
I do not claim it takes "Hours to run", I claim it may be "run for hours".
@llancet
Ah ha! See... Always calling my $thr on occasion seems to overwrite / invalidate the older thread. When checking memory usage using my $thr, it never seems to increase which is very odd to me.
@rjt
Thanks for the code, however the script is "always running" and does not ever exit.
Perhaps the actual code will shed some light on what is really going on. Its attached below.
Keep in mind the same problem still exists. How to ensure this is a FRESH thread (as my or the same $thr will eventually crash), without wasting all that memory.
use threads;
do("./sql.pl"); #NOT INCLUDED IN EXAMPLE
$thr4 = threads->new(\&processor);
$thr4->detach();
sub processor{
my $select;
$select = qq~ select * from pool_process where any="1" and status
+="" order by id asc limit 1; ~;
while (1){
if ($sys_ok == 1){
sleep(1);
my @row = &row_sql($select,-1);
if (!(@row)){
#pass
}else{
&del_sql(qq~ update pool_process set status = "RUNNING",proc
+_srv="$server_id" where id="@row[0]"; ~,-1);
print "Processing (@row[1],@row[2],@row[3],@row[4])\n";
$used_threads++;
my $thr =threads->new(\&process_start,@row[1],@row[2],@row[3
+],@row[4],@row[5],@row[6],@row[7],@row[0]);
$thr->detach();
if (@row[4] eq "generate_details"){
sleep(3);
}
}
}else{
sleep(30);
}
}
}
sub process_start{
my $return_code = system(qq~ perl ./thread_process.pl "$_[0]" "$_[
+1]" "$_[2]" "$_[3]" "$_[4]" ~);
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.