J
Jeff
Hello,
I'm seeing a strange issue w/ perl in the code below.
The code below dynamically creates executable objects and passes them
along to a thread pool (written in c++, swig'd to Perl) to execute.
When execution of the object is complete, the new thread calls the perl
callback function that was provided at the time of the object's
construction.
The callback function prints the output of the executable object and
then destroys the object. The problem is that the callback function is
receiving an object that has already been destroyed.
I believe the destruction is taking place in the main creation loop,
but I'm not sure why. I think it's because I'm assigning the new
objects to the same variable over and over, and some point perl tries
to clean up this mess, and destroys the objects. And, unfortunately,
Perl is destroying the object before the callback function for one of
the objects has been processed.
Is there a way to manually increase the reference count for these
objects or a better way to go about this?
use EPEE;
#callback function
sub func()
{
my($cmd) = @_ ;
$output=$cmd->GetFormattedOutput();
printf("%s\n",$output);
$cmd->DESTROY();
}
#create threadPool
$threadPool=new EPEE::CThreadPool(32,16);
#main dynamic object creation loop
for($i=0;$i<1000000;$i++)
{
$testcmd=new EPEE::CCommand(\&func);
$threadPool->Execute($testcmd);
}
$threadPool->WaitForCompletion();
Thanks,
Jeff
I'm seeing a strange issue w/ perl in the code below.
The code below dynamically creates executable objects and passes them
along to a thread pool (written in c++, swig'd to Perl) to execute.
When execution of the object is complete, the new thread calls the perl
callback function that was provided at the time of the object's
construction.
The callback function prints the output of the executable object and
then destroys the object. The problem is that the callback function is
receiving an object that has already been destroyed.
I believe the destruction is taking place in the main creation loop,
but I'm not sure why. I think it's because I'm assigning the new
objects to the same variable over and over, and some point perl tries
to clean up this mess, and destroys the objects. And, unfortunately,
Perl is destroying the object before the callback function for one of
the objects has been processed.
Is there a way to manually increase the reference count for these
objects or a better way to go about this?
use EPEE;
#callback function
sub func()
{
my($cmd) = @_ ;
$output=$cmd->GetFormattedOutput();
printf("%s\n",$output);
$cmd->DESTROY();
}
#create threadPool
$threadPool=new EPEE::CThreadPool(32,16);
#main dynamic object creation loop
for($i=0;$i<1000000;$i++)
{
$testcmd=new EPEE::CCommand(\&func);
$threadPool->Execute($testcmd);
}
$threadPool->WaitForCompletion();
Thanks,
Jeff