in reply to Just can't get threads to work

While I have stayed away from threads in Perl, usually, you need to wait for your threads to finish before you exit with your main thread. Maybe detaching the threads also keeps the main program alive. I'd try the following for kickstarting the threads:

my @threads; my @ips = qw( 192.168.1.50 192.168.1.1 ); for my $ip (@ips) { push @threads, threads->new(\&polldevice,$ip, "public"); }; # Now, wait for all threads to finish: for my $thread (@threads) { print "Waiting for thread $thread to finish.\n"; my @results = $thread->join(); print "(got @results)\n"; }; print "All threads finished.\n";

Replies are listed 'Best First'.
Re^2: Just can't get threads to work
by stellagoddc (Novice) on Apr 20, 2006 at 16:13 UTC
    Ofcourse, the main script ends, killing the threads, doooh.

    My final script will always be running, which is why I wasn't thinking about that.

    Thanks again.