CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Intermediate: Re: [FishMonger] Thread or Fork?: Edit Log

Sam Kennedy

Aug 30, 2012, 7:18 AM

Views: 23720
Re: [FishMonger] Thread or Fork?

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


(This post was edited by Sam Kennedy on Aug 30, 2012, 8:00 AM)

Edit Log:
Post edited by Sam Kennedy (Novice) on Aug 30, 2012, 8:00 AM

Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives