Yes. 10 copies of your sub will run concurrently. And each will see it's own unique value of the closure $j.

As posted though, the process will die as soon as the last thread is started, with the infamous:

Perl exited with active threads: 10 running and unjoined 0 finished and unjoined 0 running and detached

warning, as you are not waiting for them to finish. However, the spawned mv processes will (probably, I've not used iThreads on *nix), continue running to completion.

In effect, you have coded the equivalent of:

no threads; my $j = 0; for (1..10) { $j++; `mv ./a_file$j /home/user/dir 2>&1 &`; }

Whether you will gain any throughput from using concurrency will depend upon your system, no of processors, disks, etc. but as Corion pointed out, any gains will likely be quite small.


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.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

In reply to Re: Did I create a concurrent program? by BrowserUk
in thread Did I create a concurrent program? by jweden1

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.