in reply to Re^4: perl -Dusethreads compilation
in thread perl -Dusethreads compilation

I am worried about multiple threads colliding, race condtions, in NET::FTP module.

Just create a new instance of Net:FTP in each thread. There should(untested) be no conflicts.

This untested pseudo-code might get you started:

use threads use Thread::Queue use Net::FTP my $Q = new Thread::Queue; sub downloader { my $ftp = Net::FTP->new("some.host.name", Debug => 0) or die "Cannot connect to some.host.name: $@"; $ftp->login("anonymous",'-anonymous@') or die "Cannot login ", $ftp->message; $ftp->cwd("/pub") or die "Cannot change working directory ", $ftp->message; while( my $file = $Q->dequeue ) { $ftp->get( $file ); $ftp->delete( $file ); } $ftp->quit } my @threads = map threads->create( \&downloader ), 1 .. $N; my $ftp = Net::FTP->new("some.host.name", Debug => 0) or die "Cannot connect to some.host.name: $@"; $ftp->login("anonymous",'-anonymous@') or die "Cannot login ", $ftp->message; $ftp->cwd("/pub") or die "Cannot change working directory ", $ftp->message; $Q->enqueue( $ftp->ls ) or die $!; $ftp->quit; $Q->enqueue( (undef) x $N ); $_->join for @threads;

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"I'd rather go naked than blow up my ass"

Replies are listed 'Best First'.
Re^6: perl -Dusethreads compilation
by mr_p (Scribe) on Apr 05, 2010 at 17:05 UTC
    I do have separate instance/connection. But my question is should I still be concerned about any clashing happening? Oh and this is the same server downloading.

      Try it. See what happens.

        Thanks for the code.

        I have made a package wrapper for Net::FTP the purpose is for error code checking.

        The package declares "our ftpObj", can you tell me what happens if all threads use the ftpObj, even though they make their own connections will I get conflicts because of the variable is declared as 'our'.