use threads; use threads::shared; my $sharedTestVar :shared; #### ... 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"); #### $sharedTestVar=6; $DEBUG && msg("init : set sharedTestVar == $sharedTestVar"); #### $mcastReaderThread=threads->new(\&doMcastSubscription, $interface,$mcastAddress,$mcastPort); $mcastReaderThread->detach; #### 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 == $sharedTestVar"); $drop=0; } $DEBUG && msg("leaving doMcastSubscription()"); } #### while(1) { ... msg("in main while loop, sharedTestVar == $sharedTestVar"); ... sleep(5); } #### 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; } } #### sub processMessage { ... if($FeedAgent::sendRateStats) { $sharedTestVar++; msg("in processMessage set sharedTestVar == $sharedTestVar"); } ... }