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 | |
by ikegami (Patriarch) on Mar 16, 2010 at 18:09 UTC |