I am Forking 100 Threads (5 Processes are forking 100 threads). The Problem I am facing is Hash Variables are not getting the values. Here is my code snippet:
use threads;
use threads::shared;
my %CallInfoHash : shared = ();
my $processToFork = 5;
my $threads = 100;
my %threadsHash;
for ($jj = 0; $jj < $processToFork; $jj++) {
...fork a process here:
for ($ii = 0; $ii < $threads; $jj++) {
my $callNum = $jj;
$UrlToDownload = <Some URL>;
push (@argList, $callNum );
push (@argList, $UrlToDownload);
$threadsHash{$CallNumber} = threads->create(\&tsub, @argList);
}
}
sub tsub {
.. Here some operations are done and values are generated.
These values are to be stored in %CallInfoHash Hash.
my $value1 = xx;
my $value2 = xx;
$CallInfoHash{$CallNumber}{'value1'} = $value1;
$CallInfoHash{$CallNumber}{'value2'} = $value2;
.... There are about 10 values.
}
Now when I do foreach(keys %CallInfoHash) after the process has been completed, there is no value in %CallInfoHash.
I am sure there is some issue with the shared variables but I am unable to find the solution. Please help.
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.