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

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'.

Replies are listed 'Best First'.
Re^9: perl -Dusethreads compilation
by BrowserUk (Patriarch) on Apr 05, 2010 at 21:07 UTC

    Unless you explicitly share a varible, each thread will have it's own copy.

    But, if you assign an object to a variable, before you spawn a thread, the new thread will usually not be able to use its copy successfully. It is quite hard to advise you without seeing your code.


    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 have 2 files

      1. Package wrapper for NET::FTP (error checking) 2. main code that creates threads and self master. <code> # File 1 package myFtp; use Net::FTP; use Net::Cmd; our @ftpObj; our @ftpList = (); our @code; sub Connect { my ($ftpServer, $ftpTimeout, $connection_type) = @_; #debug ("Trying -> ", $ftpServer); $ftpObj = Net::FTP->new($ftpServer, Timeout => $ftpTimeout, Passiv +e => $connection_type); return; } #other functions....
      #File 2 (Main Code) use SPFtp qw(/^\$/); use SPFtp qw (Connect Login PrepareLsFtpList deleteFile GetFile GetFil +eSize Logout GetMessage CheckConnection); # Create Thread 1 Connect("bugs", "60", "binary"); # Create Thread 2 Connect("bugs", "60", "binary"); # Create Thread 3 Connect("bugs", "60", "binary"); # Create Thread 4 Connect("bugs", "60", "binary"); # Master Thread

      Here is my question?

      Will $ftpObj Variable get screwed up? I am pretty sure it will.

        Hm. You declare our @ftpObj;; you then assign to $ftpObj = ...;; you post a 'trace', but don't show any code that produces that trace.

        Here is my question?

        Will $ftpObj Variable get screwed up? I am pretty sure it will.

        Then don't do that!

        Stop wasting my ....... time!