I am trying to use threads inside of a perl object and it isn't working. Here is the 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($swObj
+ect,$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;
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:
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);
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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.