<?xml version="1.0" encoding="windows-1252"?>
<node id="949993" title="Re^5: Need help with Perl multi threading" created="2012-01-25 18:36:52" updated="2012-01-25 18:36:52">
<type id="11">
note</type>
<author id="1382">
chromatic</author>
<data>
<field name="doctext">
&lt;p&gt;With regard to:&lt;/p&gt;

&lt;c&gt;foreach my $host ( @servers )
{
    threads-&gt;new(\&amp;process, $host )-&gt;join();
}&lt;/c&gt;

&lt;p&gt;... creating a new thread and then immediately &lt;c&gt;join&lt;/c&gt;ing it is a waste of time; &lt;c&gt;join&lt;/c&gt; waits for the thread to finish.&lt;/p&gt;

&lt;p&gt;In this case, &lt;c&gt;detach&lt;/c&gt; is probably better. Otherwise, keep an array of all threads and &lt;em&gt;after&lt;/em&gt; you've created all of them, then &lt;c&gt;join&lt;/c&gt; all of them.&lt;/p&gt;

&lt;div class="pmsig"&gt;&lt;div class="pmsig-1382"&gt;
&lt;hr /&gt;

&lt;p&gt;Improve your skills with &lt;a href="http://www.onyxneon.com/books/modern_perl/index.html"&gt;Modern Perl: the free book&lt;/a&gt;.&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
949944</field>
<field name="parent_node">
949981</field>
</data>
</node>
