That's great thanks very,very much for replying : )

Your code does indeed work but if I try to use the same methodology in my code it doesn't. I get :

Thread 1 terminated abnormally: lock can only be used on shared values + at UTP.pm line 189 <c> Do you think this is because of the separate package ?? I declare and initialise the hash in MdAgent.pl : <c> ... my %Totals :shared; ... msg("initialising totals"); foreach my $envo(sort keys %{$marketMsgHsh{$plugin}{environments}}) { $DEBUG && msg("sharing $envo"); $Totals{$envo}=&share( {} ); $DEBUG && msg("done."); foreach my $messageType(sort keys %{$marketMsgHsh{$plugin}{message +Types}}) { $Totals{$envo}{$messageType}=0; } } msg("done."); ...
...and then after that I create the thread :
... $mcastReaderThread=threads->create(\&doMcastSubscription, $interface, +$mcastAddress, $mcastPort); $mcastReaderThread->detach(); ...
in the thread I call the sub(in the "UTP" package)that actually handles the messages :
... while(1) { $drop=1 unless $peer->recv($sock, $message, $maxLen,0) if($drop ==1) { $DEBUG && msg("recv failed : $!"); } else { $actualPlugin->processMessage("$message"); } ...
processMessage is defined in "UTP.pm". this is what I have it doing right now :
... if($FeedAgent::sendRateStats) { lock %{$Totals{$serviceID}}; $Totals{$serviceID}{$packetType}++; $DEBUG && msg("set Totals{$serviceID}{$packetType} == $Totals{ +$serviceID}{$packetType}");; } ...
Is this going wrong because the processMessage sub is in a different package or am I doing something else wrong ??

In reply to Re^2: communication across threads using hash of hashes by stevehicks
in thread communication across threads using hash of hashes 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.