Hello

I ran into a strange (to my eyes) behaviour of perl 5.8s threads. Maybe I'm just doing things wrong or have the wrong impression on how things are meant to work.

I'm using 5.8 threads and Net::FTP, to execute one command on a couple FTP Servers at the same time. After connecting to all FTP Servers and storing the connect hash, i create a thread for every FTP to execute a command. It seems to me that when creating the threads to execute the command, the threads are blocking. Eg the commands don't happen in parallel but in serial.

I would be glad if someone could enlighten me if I misunderstood something about the threading implementation of perl, or if i'm doing something seriously wrong about the threads. The whole thing is running on RH7.2 with perl compiled from cpan.

Here some snippets of my code (the whole thing is too big to paste here):

## @ftp is an array holding the name of the respective ftp servers for ($i=0;$i<scalar(@ftp);$i++) { $ftpconnect[$i] = ftp_connect($host[$i],$port[$i],$user[$i],$pass[ +$i],$dir[$i]); } for ($i=0;$i<scalar(@ftp);$i++) { $thread[$i] = threads->create("ftp_exec",$ftpconnect[$i],$command[ +$i]); ## this is where it seems it's blocking? or just taking an awful l +ong time to create each thread. ## although it's necessary that the commands get executed at the e +xact same time everywhere. } ######## maximum time a command takes is around 30 seconds ######## sleep(30); for ($i=0;$i<scalar(@ftp);$i++) { $thread[$i]->join(); } ### subs sub ftp_connect { my ($remoteHost, $remotePort, $remoteUser, $remotePwd, $remote +dir) = @_; my $ftp = Net::FTP->new($remoteHost,Port=>$remotePort,Debug=>1 +); if ($ftp) { $ftp->login($remoteUser,$remotePwd); if (!$ftp->cwd($remotedir)) { $ftp->quit; return ("dir +ectory doesn't exist?"); } $ftp->type('I'); } return ($ftp); } sub ftp_exec { my ($ftp,$cmd) = @_; $ftp->quot("$cmd"); $ftp->quit(); }

thanks in advance
.emanuel


In reply to 5.8 threads blocking/slow by Emanuel

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.