multithreading - Running perl subroutine in parallel with Coro -
I have a sub-root that I executed parallel with kero
:
hard; Use warnings; Use Koro; Sub MySubub {my ($ in) = @_; Print "$ in \ n"; My $ i ($ 0.01 million) before $$ {$ i = $ i + 1; } Return 1; How can I make threads from
to
(async {mysub "A"}), (async {mysub "B" }}, {Async {mysub "C"}), (async {mysub "X"}), (async {mysub "Y"})) {$ _- & gt; contains;}
However, threads have been created but how can I run them in parallel? The example shows that (or better AnyEvent :: socket
) makes parallel execution possible, but how do I In my simplest example can I?
Apart from this (but this is the second question), the above-the-loop Why is the argument for mysub
but not in the example below?
my @letters = ("A", "B", "C" , "X", "y"); my @in = map {(async {mysub $ _}}} @ bars; (@in) {$ _- & gt; join};
Koro is a cooperative multitasking system. A thread will only handover the second to the CPU when the program explicitly does this. , Or when it stopped waiting for any event in a core-aware call Ia is.
For example, wait at parallel to the following HTTP responses:
Use the coo queue (async); LWP :: Protocol :: Use anyEvent :: http qw (); Use LWP :: User Agent QW (); ... my $ url (@urls) {async {process ($ ua- & gt; get ($ url))}; } ...
The core is powerless to divide the arithmetic between the CPUs, since it is not making any OS thread since trying your example.
Comments
Post a Comment