Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re^5: Need help with Perl multi threading

by chromatic (Archbishop)
on Jan 25, 2012 at 23:36 UTC ( #949993=note: print w/replies, xml ) Need Help??

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.


      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.

        I am able to run the scripts with Net:;OpenSSH module having the statements like threads->create()->join(). may be it is not a good idea but the script execution time drastically changed and my script is also working as I want.....

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://949993]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2018-05-20 16:53 GMT
Find Nodes?
    Voting Booth?