print $thr->join(); should print out my start_thread sub return value of
return "juhu";
but it does not because of image magick
i tried to create an easier example:
Code: Select all
use strict;
use threads;
use Image::Magick;
my $x = new Image::Magick;
$x -> ReadImage("xc:white");
#undef $x;
startThreads();
print "DONE!\n";
sub startThreads{
print "Start of start threads \n";
my $thr = threads->create('threadSub', '1');
my $thr2 = threads->create('threadSub', '2');
print $thr->join();
#$x -> ReadImage("xc:white");
print $thr2->join();
print "End of start threads \n";
}
sub threadSub {
my @args = @_;
print('Thread started: ', join(' ', @args), "\n");
sleep(1);
print('Thread ended: ', join(' ', @args), "\n");
return "return value (".join(' ', @args).") \n";
}
1;
result:
Code: Select all
Start of start threads
Thread started: 1
Thread started: 2
Thread ended: 1
return value (1)
Thread ended: 2
perl: magick/image.c:1611: DestroyImage: Assertion `image->signature == 0xabacadabUL' failed.
Aborted
in line 8 I wrote: #undef $x;
if you change it to undef $x;
the code will work:
Code: Select all
Start of start threads
Thread started: 1
Thread started: 2
Thread ended: 1
return value (1)
Thread ended: 2
return value (2)
End of start threads
DONE!
now please change line 8 back to #undex $x and change line 20
from #$x -> ReadImage("xc:white"); to $x -> ReadImage("xc:white");
you will see this output:
Code: Select all
Start of start threads
Thread started: 1
Thread started: 2
Thread ended: 1
return value (1)
Thread ended: 2
return value (2)
End of start threads
perl: magick/image.c:1611: DestroyImage: Assertion `image->signature == 0xabacadabUL' failed.
Aborted
so I guess the imageMagick fails because of this:
$x is created global in the main perl thread
two further threads are started
1. thread is done and ->join() destroys it. ImageMagick
destroys $x
2. thread is done and ->join() destroys it. ImageMagick and
can't destroy $x and dies.
Now here is my question:
why does it destroy a global that is neither initialized nor used in this thread?