What are the alternatives to Perl interpreter threads? What are the alternatives to Perl interpreter threads? multithreading multithreading

What are the alternatives to Perl interpreter threads?


Depends on what you're trying to accomplish. I still use threads extensively, and there isn't a massive problem with them.

The biggest problem with them is that they are not lightweight, where if you've threaded in other languages, you might expect them to be.

They're more the opposite - spawning a thread is like starting your code again, but with some useful hooks for IPC. That means you really don't want to be doing a task-per-thread model of program, like you might be thinking of.

Instead, you would be much better served by a Thread::Queue worker-thread style model. Here's an example of that:Perl daemonize with child daemons

However, you may want to consider using fork as an alternative. fork - because of it's implementation on Unix - is a very efficient system call, and can be quite efficient for spawning new processes. The downside is - it's not quite as friendly for doing IPC.

Parallel::ForkManager is one module that I like for doing forking for multiprocessing.

But in either case you should note - multiprocessing isn't a magic bullet. It lets you hog more CPUs if you have the right sort of problem to solve. It won't make your disks go any faster :)


That warning is poppycock. It should be removed. The developers of Perl explained that it means "The use of interpreter-based threads in perl is officially discouraged if you want a lightweight system for multitasking".

Since creating new threads can be expensive, just use a model that involves reusable worker threads.


As long as I know, there are not any reliable thread implemantations. You should stick to some event-based modules, like Coro, AnyEvent, IO::Async etc.