Update: please note I'm talking about threads in the general sense. See my clarification on Perl threads.

I don't see the appeal of threads. Modern kernels on CPUs with modern MMUs can fork processes with very little effort and switch them pretty quickly. I expect the performance will increase further with time.

I don't even care that much about the performance argument - but it used to be a big problem once upon a time long past, so I thought I should get that out of the way first.

And then there's the real argument: safety. Forked processes default to not sharing; threads default to sharing everything. With the former, you have to explicitly share what you desire to be shared while with the latter you have to explicitly make thread local copies of sensitive data.

Every person in their right mind will tell you that the correct approach to security is to disallow by default and exempt desired interactions. Every Perl programmer worth their salt untaints data by denying anything but explicitly permitted input. The list goes on; the correct approach is always to disallow by default and explictly permit where desired.

Threads break this fundamental principle.

This is hard to argue with - by using threads you inevitably expose yourself to potential for all sorts of bugs. Since correctness is the primary concern in software development, and all else is secondary, I don't really see any choice but forking.

The current state of affairs is not perfect of course; shared memory or other forms of IPC are harder to use in practice than they ought to be.

Makeshifts last the longest.


In reply to Re: Why use threads over processes, or why use processes over threads? by Aristotle
in thread Why use threads over processes, or why use processes over threads? by pg

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.