Coro-Multicore
view release on metacpan or search on metacpan
Multicore.pm view on Meta::CPAN
Since this module integrates into an event loop and you must not normally
block and wait for something in an event loop callbacks. Now imagine
somebody patches your favourite module (e.g. Digest::MD5) to take
advantage of of the Perl Multicore API.
Then code that runs in an event loop callback and executes
Digest::MD5::md5 would work fine without C<Coro::Multicore> - it would
simply calculate the MD5 digest and block execution of anything else. But
with C<Coro::Multicore> enabled, the same operation would try to run other
threads. And when those wait for events, there is no event loop anymore,
as the event loop thread is busy doing the MD5 calculation, leading to a
deadlock.
=head2 USE IT IN THE MAIN PROGRAM
One way to avoid this is to not run perlmulticore enabled functions
in any callbacks. A simpler way to ensure it works is to disable
C<Coro::Multicore> thread switching in event loop callbacks, and enable it
everywhere else.
Therefore, if you control the event loop, as is usually the case when
Since this module integrates into an event loop and you must not
normally block and wait for something in an event loop callbacks. Now
imagine somebody patches your favourite module (e.g. Digest::MD5) to
take advantage of of the Perl Multicore API.
Then code that runs in an event loop callback and executes
Digest::MD5::md5 would work fine without "Coro::Multicore" - it would
simply calculate the MD5 digest and block execution of anything else.
But with "Coro::Multicore" enabled, the same operation would try to run
other threads. And when those wait for events, there is no event loop
anymore, as the event loop thread is busy doing the MD5 calculation,
leading to a deadlock.
USE IT IN THE MAIN PROGRAM
One way to avoid this is to not run perlmulticore enabled functions in
any callbacks. A simpler way to ensure it works is to disable
"Coro::Multicore" thread switching in event loop callbacks, and enable
it everywhere else.
Therefore, if you control the event loop, as is usually the case when
you write *program* and not a *module*, then you can enable
( run in 0.585 second using v1.01-cache-2.11-cpan-87723dcf8b7 )