How to make a perl thread without copying all the variables?

I have one perl program where using some form of parallelism will really be useful.

However, I have quite a lot of data in variables that I do not need at all in this part of the program.

If I use perl streams, it copies all the variables every time I create a new stream. In my case, it hurts a lot.

What should I use to create a new stream without copying? Or are there some better thread implementations that don't copy everything?

+6
multithreading perl
source share
3 answers

Like syntax, lightness of threads, but not all fat? Use the awesome forks module! It implements a thread interface using fork and IPC, which makes it easy to exchange data between child processes.

+7
source share

Indeed, you just need to avoid ithreads. They are terrible, and unlike any other form of thread on the planet, they are more expensive than ordinary heavy processes. My preferred solution is to use an event-based framework like POE or AnyEvent (I use POE) and rip out any tasks that cannot be made non-blocking in subprocesses using POE :: Wheel :: Run (or fork_call for AnyEvent). To write the application in this case requires more design work, but done correctly, this will give you effective code. From time to time, I also wrote code that simply uses fork and pipe (or open '-|' ) and IO::Select and waitpid directly within my own event loop, but you should probably consider that the symptom I learned is C up to perl, not a recommendation. :)

A word for the wise though: if you work on Windows, then this approach can be almost as bad as using ithreads directly, since Perl compensates for the lack of win32 fork() with iithreads, paying the same cost of creating iread (on CPU and memory) on each fork . This is actually not a good solution.

+4
source share
+3
source share

All Articles