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:
Thread vs. Fork
Threads vs Forking (Java vs Perl)
Threads, Forks, or Nothing?
Multithread / Fork Perl Examples.
To thread or not to thread
Status and usefulness of ithreads in 5.8.0
ActiveState, threaded fork and re-entrancy
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.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Threads versus fork, which to use?
by pg (Canon) on Feb 08, 2003 at 05:59 UTC | |
Re: Threads versus fork, which to use?
by Juerd (Abbot) on Feb 07, 2003 at 21:04 UTC |