http://www.perlmonks.org?node_id=949993


in reply to Re^4: Need help with Perl multi threading
in thread Need help with Perl multi threading

With regard to:

foreach my $host ( @servers ) { threads->new(\&process, $host )->join(); }

... creating a new thread and then immediately joining it is a waste of time; join waits for the thread to finish.

In this case, detach is probably better. Otherwise, keep an array of all threads and after you've created all of them, then join all of them.


Improve your skills with Modern Perl: the free book.

Replies are listed 'Best First'.
Re^6: Need help with Perl multi threading
by ashok.g (Beadle) on Jan 27, 2012 at 11:55 UTC
    This was completely opposite to the comment posted in this node

    Anyways I got my task completed by using Net::OpenSSH.

    Thanks,
    Ashok

      BrowserUK and I said essentially the same thing. If you write your thread code as you did, you're not getting any advantage of threading. All of your threads will run serially.

      A reply falls below the community's threshold of quality. You may see it by logging in.