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:
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.


In reply to Threads versus fork, which to use? by rinceWind

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.