
Sam Kennedy
Novice
Aug 30, 2012, 7:18 AM
Post #5 of 21
(18193 views)
|
Re: [FishMonger] Thread or Fork?
[In reply to]
|
Can't Post
|
|
Thank you very much! :D I've been playing around with the Threads and Threads shared module and figured out how it works, I should have no problem implementing this in my code now :) EDIT: It turns out I will need to share an object, I've shared the variable and the array which are used to create the object, but my code keeps crashing. This is how I declared my variables etc.:
my $timage :shared; my $width :shared; my $height :shared; my @im :shared; my @score :shared; This is the first object being created:
$timage = GD::Image->newFromPng("ml.png"); ($width, $height) = $timage->getBounds; And the final objects being created:
for(my $i = 1; $i <= $population; $i++){ $im[$i] = new GD::Image($width,$height,1); ... ... They are accessed in the thread like this:
my ($index1) = $timage->getPixel($x,$y); #My code crashes on this line my ($index2) = $im[$_[0]]->getPixel($x,$y); Is there a problem in the way I'm sharing the object, the way I'm accessing it, or both? Thank You -Sam -Sam
(This post was edited by Sam Kennedy on Aug 30, 2012, 8:00 AM)
|