in reply to Did I create a concurrent program?

Your mytest routine will run concurrently, but you have a race condition. You should pass the value of $j into the thread at thread creation time instead of accessing a global variable. As your threads run, there is a chance that two threads will try to use the same value in $j to move a file. Also, there is little sense in using threads for IO operations, as IO operations that use the full bandwidth of the bus available seldom benefit from parallelization.

Replies are listed 'Best First'.
Re^2: Did I create a concurrent program?
by JavaFan (Canon) on Nov 19, 2008 at 14:05 UTC
    Your mytest routine will run concurrently, but you have a race condition. You should pass the value of $j into the thread at thread creation time instead of accessing a global variable. As your threads run, there is a chance that two threads will try to use the same value in $j to move a file.
    Aren't Perl variables supposed to be non-shared by default?
Re^2: Did I create a concurrent program?
by jweden1 (Initiate) on Nov 19, 2008 at 22:30 UTC
    Thanks, I didn't consider that. Thanks for all the advice everyone. I had a problem doing something like this:
    threads->create(\&mytest($j));
    ...and then reading in $j via @_ in the subroutine. This may have something to do with passing by reference via \&? Sorry, I forget what the error was but it wasn't allowed. Any ideas why?