
adamcpfeiffer
New User
Jul 2, 2013, 5:42 PM
Post #1 of 1
(2480 views)
|
How do I use threads inside an Object
|
Can't Post
|
|
I am trying to use threads inside of a perl object and it isn't working. Here is the code: <code> 120 sub _openFDCObject 121 { 122 my $self = shift; 123 my $swObject = shift; 124 my $switch = shift; 125 my $fdcObject = FosDataCapture->new($log, $swObject); 126 return ($fdcObject, $switch); 127 } 128 129 sub getFDCObjects 130 { 131 my $self = shift; 132 my %fdcObjectHash; 133 my @threadQueue; 134 my %switches = $self->getSwitches(); 135 for my $switch (keys %switches) 136 { 137 #my $fdcObject = $self->_openFDCObject($switches{$switch}, $switch); 138 my $swObject = $switches{$switch}; 139 my $thread = threads->create(\$self->_openFDCObject($swObject,$switch)); 140 push(@threadQueue, $thread); 141 #$fdcObjectHash{$switch} = $fdcObject; 142 } 143 foreach my $thread (@threadQueue) 144 { 145 my ($fdcObject, $switch); 146 ($fdcObject, $switch) = $thread->join(); 147 $fdcObjectHash{$switch} = $fdcObject; 148 } 149 return %fdcObjectHash; </code> What I don't know is how I format line 139 to call the subroutine that is part of the object. I have tried the following: <code> my $thread = threads->create(\$self->_openFDCObject($swObject,$switch)); my $thread = threads->create(\$self->_openFDCObject,$swObject,$switch); my $thread = threads->create($self->_openFDCObject,$swObject,$switch); my $thread = threads->create(&_openFDCObject,$swObject,$switch); </code> The first one above does run, but I don't see any threading happening. The other invocations don't pass $swObject and $switch to the subroutine _openFDCObject. Please let me know if you need any further information. Thanks
|