Concurrent Execution#
Doing work in parallel, or several things at once. There are three concurrency stories to know about, and they answer different questions:
Auto-parallelization -
pperl’s runtime detects parallelisable patterns in ordinary Perl and spreads them across cores without any user-level threading. This is the preferred answer for CPU-bound loops over large data.Coroutines and event loops - Coro, EV, Event and AnyEvent: many tasks that mostly wait - on sockets, timers, child processes - each written as straight-line code, taking turns in one interpreter. The answer for I/O-bound concurrency.
Classical ithreads (not implemented) - Perl 5’s
threadsandthreads::sharedmodel. pperl deliberately does not provide it:use threadsfails at compile time. The chapter teaches the model so that you can read existing code, and most programs that used ithreads are better rewritten against the auto-parallel path.
Start with the decision chapter if you have an existing threaded program and are deciding how to port it; start with parallel if you are writing new code and want to understand when pperl speeds your loop up, and with coroutines if your program spends its time waiting.