in reply to Re^3: wait for threads to end in parallel
in thread wait for threads to end in parallel

Ah yes, I forgot about that. Revised answer:


Syntax. async is shorter, and it simply pass args via capture. That's good, because passing args to a thread as arguments is known to be problematic*.

Without args:

async(\&process); async { process(); }; thread->create(\&process);

With args:

async(\&process, $arg); # Safe?? thread->create(\&process, $arg); # Safe?? async { process($arg); }; thread->create(sub { process($arg) });

* — The stack isn't ref-counted, and this causes issues when thread creation attempts to clone the variables. I can't remember the exact scenario, but I can look it up if you want more info.

Replies are listed 'Best First'.
Re^5: wait for threads to end in parallel
by BrowserUk (Patriarch) on Mar 16, 2010 at 17:11 UTC
    The stack isn't ref-counted, and this causes issues when thread creation attempts to clone the variables. I can't remember the exact scenario, but I can look it up if you want more info.

    If you have a moments at some point, I would be interested to read about it. Thanks.


    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.

      Ah, there it is: RT 70602. The problem was a noisy memory leak.

      Apparently, it's fixed in 5.12.