in reply to Re^2: Object Functions and Threading
in thread Object Functions and Threading
Be aware. Doing this is deceptive.
my $downloader = eval { new Downloader() } or die($@); print $downloader; ## This will be a different instance my $thread1 = threads->new( sub { print $downloader; ### to this one $downloader->fetch("http://www.webaddress.com", \%siteHash); ## +<< This ## Will be a different hash to any similarly named hash above ## unless it was shared. } ); ## Unless you are doing other stuff here, ## this is just an exspensive synchronous call :) $thread1->join;
That would be better coded as
my %siteHash : shared; my $thread = threads->new( sub { my( $address, $hashref ) = @_; my $downloader = eval{ Downloader->new } or die $@; $downloader->fetch( $address, $hashref ); }, $address, \%siteHash ) or die $!; ## do other stuff $thread->join;
|
|---|