in reply to Re^2: Need help with Perl multi threading
in thread Need help with Perl multi threading
Sorry to be rude, but you really don't seem to have a clue what you are doing.
This is a completely redundant use of threading:
push (@threads, threads->new(\&Process_Output, $ssh, $proc )); while ( $thread = shift @threads ) { @output=$thread->join(); }
You create a thread and push its handle onto @threads. You then immediately shift that handle off of the array and join it.
It is exactly equivalent to:
$thread = threads->new(\&Process_Output, $ssh, $proc ); if( $thread ) { @output = $thread->join(); }
Which is equivalent to :
$thread = threads->new(\&Process_Output, $ssh, $proc ); @output = $thread->join();
Which is exactly equivalent to this:
@output = threads->new(\&Process_Output, $ssh, $proc )->join();
Which is exactly equivalent to:
@output = Process_Output( $ssh, $proc );
Except that the latter will work. (Of course, it won't speed things up. But neither will what you have now.) But it will work.
The reason your code is crashing is because you are creating an instance of Net::SSH::Expect in one thread, and trying to use it in another.
Why? Why not create the object in the thread where you are going to use it?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Need help with Perl multi threading
by ashok.g (Beadle) on Jan 25, 2012 at 21:41 UTC | |
by BrowserUk (Patriarch) on Jan 25, 2012 at 22:20 UTC | |
by ashok.g (Beadle) on Jan 25, 2012 at 23:01 UTC | |
by BrowserUk (Patriarch) on Jan 26, 2012 at 07:30 UTC | |
by ashok.g (Beadle) on Jan 27, 2012 at 11:57 UTC | |
| |
|
Re^4: Need help with Perl multi threading
by ashok.g (Beadle) on Jan 25, 2012 at 21:52 UTC | |
by chromatic (Archbishop) on Jan 25, 2012 at 23:36 UTC | |
by ashok.g (Beadle) on Jan 27, 2012 at 11:55 UTC | |
by chromatic (Archbishop) on Jan 27, 2012 at 20:09 UTC | |
by ashok.g (Beadle) on Jan 30, 2012 at 16:35 UTC | |
|