Saladino has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to stop a capture thread from another thread breaking the $capobjects loop, for that I need to share that variable, but it fails with the share:
thread failed to start: Invalid value for shared scalar at test.pl line 22. (open_live line)
Thank you for your timeuse threads; use threads::shared; use Net::Pcap; my $capobj:shared = (); my $capthread = threads->new(\&capture); sleep 3; Net::Pcap::breakloop($capobj); sub capture { my $err; my $dev = Net::Pcap::lookupdev(\&err); my ($address,$netmask); Net::Pcap::lookupnet($dev,\$address,\$netmask,\$err); my $filter; $capobj = Net::Pcap::open_live($dev,1024,0,0,\$err); Net::Pcap::compile($capobj,\$filter,'host XX.XX.XX.XX && port +7777 && udp',1,$netmask); Net::Pcap::setfilter($capobj,$filter); Net::Pcap::loop($capobj,0,\&capture_callback, 0); Net::Pcap::close($capobj); } sub capture_callback { .... }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Shared variables between threads
by zentara (Archbishop) on Nov 02, 2007 at 16:21 UTC | |
Re: Shared variables between threads
by BrowserUk (Patriarch) on Nov 02, 2007 at 17:29 UTC | |
by Saladino (Beadle) on Nov 05, 2007 at 09:40 UTC | |
by BrowserUk (Patriarch) on Nov 05, 2007 at 09:52 UTC | |
by Saladino (Beadle) on Nov 05, 2007 at 10:36 UTC | |
by BrowserUk (Patriarch) on Nov 05, 2007 at 11:00 UTC | |
| |
Re: Shared variables between threads
by renodino (Curate) on Nov 02, 2007 at 15:50 UTC | |
Re: Shared variables between threads
by NetWallah (Canon) on Nov 02, 2007 at 16:08 UTC | |
by Saladino (Beadle) on Nov 02, 2007 at 16:25 UTC |
Back to
Seekers of Perl Wisdom