http://qs321.pair.com?node_id=1107555


in reply to Trying to Understand the Discouragement of Threads

Threads have a big issue: they are not encapsulable.

You can not blindly create a thread in the middle of your program because doing it duplicates all the structures in the program memory. If your script is using 1Gb of memory and you create a thread, it immediately goes to 2Gb and if then you create another thread, it goes to 3Gb, etc. Replicating those data structures may also be quite expensive in terms of CPU usage.

For instance, imagine you want to query several HTTP servers in parallel. Threads look like a good match for that, so you build a module using threads, you test it and it runs fine. But then, when you use it from some data processing script that holds big datasets in memory everything goes nuts.

With the current thread support in Perl you can only use them at the high level designing your program around.