ports/86687: Perl ithreads coredump

John Gillis zefram at zefram.net
Sat Oct 1 12:58:50 PDT 2005


	Here's a sample script that creates the same core dump. It creates
50 threads that look up 1000 hostnames from a database of unique
hostnames. They are all unique. It then just runs gethostbyname.
	The actual script uses IO::Socket::INET... but I didn't want to
connect to so many hosts at once.. Without further adieu, here's the
script:

#!/usr/bin/perl -w

use threads;
use Socket;

$SIG{INT}                = \&catch_die;

my @threads;
my $shutdown :shared = 0;

for (1 .. 50) {
  shift @threads, threads->new(\&thr);
}

sub thr {
  my $i   = 0;
  my $dbi = DBI->connect("DBI:mysql:database=spider","xxx","xxx") or
die "Unable to connect to MySQL: $!\n";

  my $sth = $dbi->prepare("SELECT id, host FROM site LIMIT " .
(threads->tid * 1000) . ", 1000");
  $sth->execute;

  return if !$sth->rows;

  while ($shutdown == 0 && $i < 999) {
    my @row   = $sth->fetchrow();
    my $host  = $row[1];
    my $iaddr = gethostbyname($host) || print "Host $host not found.";
    $i++;
  }
}

while ($shutdown == 0) {
  sleep(5);
}

print "Waiting for threads\n";

foreach $thread (@threads) {
  $thread->join;
}

sub catch_die {
  # Shit. Gotta clean our act up.
  print "Closing once current page has been indexed.\n";
  $shutdown = 1;
}



More information about the freebsd-perl mailing list