Thanks very much for your help guys. I'vd spent a while messing around with this and it does appear that it is because of the seperate package. To make things simpler I've used a scalar. This is the scene :

I declare the shared var in the main program :
use threads; use threads::shared; my $sharedTestVar :shared;
I then "require" at rumtime the plugin name(which equates to a module) that was passed as a parameter to the program :
... if(! GetOptions ('plugin=s' => \$plugin,'config=s' => \$instanceName,' +debug' => \$debug, 'interface=s' => \$interface, 'mcastAddress=s' => +\$mcastAddress, 'mcastPort=s' => \$mcastPort, 'file=s' => \$snoopf, ' +remotePcapForwarder=s' => \$remotePCF, 'netprobe=s' => \$netprobe)) { usage(); xit("incorrect options specification", 99); } if($debug) { msg("info : turning on debug"); $ENV{TRACE}=1; $DEBUG=1; } if(! $plugin) { usage(); xit("you must supply a plugin name", 98); } msg("info : plugin \"$plugin\" will be connected"); eval (require "$PALIBDIR/$plugin.pm");
I then assign a value to the test scalar :
$sharedTestVar=6; $DEBUG && msg("init : set sharedTestVar == $sharedTestVar");
I then create a thread and detach it :
$mcastReaderThread=threads->new(\&doMcastSubscription, $interface,$mca +stAddress,$mcastPort); $mcastReaderThread->detach;
In the doMcastSubscription sub I increment the scalar :
sub doMcastSubscription { ... while(1) { my($message,$peer); $drop=1 unless $peer=recv($sock,$message,1400,0); if($drop == 1) { $DEBUG && msg("recv failed"); #sleep(2); } else { $actualPlugin->processMessage("$message"); } $sharedTestVar++; msg("in doMcastSubscription set sharedTestVar == $sharedTestVa +r"); $drop=0; } $DEBUG && msg("leaving doMcastSubscription()"); }
meanwhile I look at the scalar in the main loop of the program :
while(1) { ... msg("in main while loop, sharedTestVar == $sharedTestVar"); ... sleep(5); }
When I do the above, it works fine, i.e the thread updates the shared scalar with no issue. However, when I move the code that increments the scalar to the file that I "required" at runtime it doesn't work. Here's what the thread is doing now :
sub doMcastSubscription { ... while(1) { my($message,$peer); $drop=1 unless $peer=recv($sock,$message,1400,0); if($drop == 1) { $DEBUG && msg("recv failed"); #sleep(2); } else { $actualPlugin->processMessage("$message"); } $drop=0; } }
and here's the processMessage sub in UTP.pm :
sub processMessage { ... if($FeedAgent::sendRateStats) { $sharedTestVar++; msg("in processMessage set sharedTestVar == $sharedTestVar"); + } ... }

I've tried declaring the shared scalar with "our" instead of "my" but this doesn't help either and not not sure what else to do as this is way past my understanding : * (

Any ideas ?? My only thought for a workaround is to use shared memory but I'd rather not

Once again thanks for trying to help, I really appreciate it !!


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.