Hi

I am writing a small app that listens to UDP datagrams sent to it from different sources and matches them up. It has a couple of threads between which it needs to share hash elements, however, I can't seem to update the hashes properly.

- the main thread listens to the messages from 3 different sources. For each mesaage it creates an entry in a dedicated hash for the given source.

- the second thread wakes up and is supposed to look at the three dedicated hashes and match up messages from each.

I am only dealing with the messages from one of these sources for now, until I can get it working.

In "main" I declare the hash for the "orc" messages and assign a "dummy" element to it that consists of a key, and a value that is another hash :

my %orcPriceHsh:shared=1; my %signatureHsh:shared = ("DE00084695946" => "0000000000.000000"); $orcPriceHsh{"0000000000"} = \%signatureHsh;

I then call the sub that listens to the messages across the network :

handleMessages($configHsh{General}{ListenPort},%orcPriceHsh);

...and spawn a thread that is supposed to look at the nested hash :

$transitCalcThread=threads->new(\&calcTransitTimes, $XmlRpcClient,$itr +sQueue,%orcPriceHsh); $transitCalcThread->detach;

in handleMessages() I assign the passed nested hash to a var "%oph" :

sub handleMessages { my $port=shift(); my %oph=@_;

...and whenever I "hear" an "orc" message I create a shared hash and add it to the top-level hash : (signature, is for example "DE0008469594621896219.525, and timeStmap is, for example "1282132286.326053", nixSeconds is, for example "1282132286,")

my %sHsh:shared = ($signature => $timeStamp); $oph{$nixSeconds} = \%sHsh;

I can dump the nested hash inside this function ok :

msg("in handleMessages() oph :"); dump(%oph);

gives :

12:51:32 : dump of oph in handleMessages() : ( 1282132292, { # tied threads::shared::tie "DE0008469594621896219.526" => "1282132292.211252", }, 1282132287, { # tied threads::shared::tie "DE00084695946218362192" => "1282132287.43417", }, 1282132286, { # tied threads::shared::tie "DE00084695946218662192" => "1282132286.326053", }, 1, undef, 0, { # tied threads::shared::tie DE00084695946 => "0000000000.000000", }, 1282132290, { # tied threads::shared::tie "DE00084695946218362192" => "1282132290.969117", }, )

but even tho the thread running calcTransitTimes() can see the initial "dummy" element it cannot see the others. This code in said function :

sub calcTransitTimes { my $XmlRpcClient=shift(); my $itrsQueue=shift(); #my %orcPriceHsh=shift(); my %args=@_; ... msg("in calcTransitTimes() args :"); dump(%args);

gives me :

12:51:32 : in calcTransitTimes() args : ( 1, undef, 0, { # tied threads::shared::tie DE00084695946 => "0000000000.000000", }, )

I know there is probably a very simple answer but I have burned a load of time on this already and I have a rapidly approaching deadline to meet. Any help would be greatly appreciated : * }


In reply to Help !! problems sharing a nested hash across threads by stevehicks

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.