Come for the quick hacks, stay for the epiphanies. | |
PerlMonks |
Threads versus fork, which to use?by rinceWind (Monsignor) |
on Feb 07, 2003 at 17:24 UTC ( [id://233532]=perlmeditation: print w/replies, xml ) | Need Help?? |
Note: I have posted this a meditation, since the question is rhetorical. Yesterday, I asked for some help on the Chatterbox, building an ithreaded perl 5.8.0 on Solaris (which I still have not achieved). This prompted a response from merlyn, of the form "threads, threads, threads... Why is everyone obsessed with threads?" There followed dscussion on the CB on the merits of threading and forks. I attended a London Perl Mongers meeting last night, and discussed the subject some more over beers.
The subject has been raised many times before on SoPW:
My conclusion is that it really depends on exactly what you are trying to achieve in the multitasking. If the tasks are completely separate, they would benefit from separate address space, hence fork. Unfortunately on Windows, you haven't got a real fork, so perl does the best it can under the circumstances. If what you want is cooperating tasks with much communication, such as shared memory structures, threads are a better model. The ithreads mechanism provides all the primitives to achieve locking etc. using method calls. Child processes can talk to each other, but you need to use an IPC mechanism such as pipes.
Back to
Meditations
|
|