Hi All.
I am writing a perl program that will read a list of configuration files in a directory and open a separate thread for each file. This thread sub will open a UDP socket, send a special message, and wait TIMEOUT time for response. After opening all the threads I am waiting to all the threaded subs to finish. Here is a snippet of the code (In which I suspect I have a problem):
my @threads;
my $thread;
my $rc;
while (@threads = threads->list()) {
foreach $thread (@threads) {
if ($thread->is_joinable()) {
$rc = $thread->join();
# Send the opcmon
# $rc->[0] is the return code.
# $rc->[1] is the nodeName the thread worked on.
&sendOpcmon($tag, $rc->[0], $rc->[1]);
}
}
# To prevent the hard CPU lookups
sleep(1);
}
#
sub sendRequest {
require IO::Socket::INET;
#IO::Socket::INET->import(...);
my ($msg, $peerAddr, $peerPort) = @_;
my $eTime = time() + TIMEOUT;
my $host = (split/\./, $msg)[0];
# configure the socket.
$MySocket = new IO::Socket::INET->new( PeerPort => $peerPort,
Proto => 'udp',
PeerAddr => $peerAddr,
);
ioctl($MySocket, 0x8004667e, pack("I", 1));
# Send the request.
$MySocket->send($msg);
# Now we will wait till the server will respond to our request.
while(time() < $eTime)
{
$MySocket->recv($text,128);
if($text =~ /OK/) {
return [1, $host];
}
# Sleep for 2 secs just to free up a %CPU usage
sleep 2;
}
# We reached the timeout, probably no response will arrive.
return [0, $host];
}
Unfortunately my code crashes the interpreter (in the $thread->join() call) with the error: "Free to wrong pool 1825cf0 not ff during global destruction".
I read some questions related to this issues here in the forum but unfortunately couldn't find a solution.
Can it be that IO::Socket::INET isn't threadsafe ?
If so, what is the best way to implement that ?
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.