Creating a new process can be expensive. It takes time. (A call into the operating system is needed, and if the process creation triggers process rescheduling activities, the operating system's context-switching mechnism will become involved.) It takes memory. (The entire process must be replicated.)

This is somewhat of a misnomer - Whilst early versions of UNIX typically copied each writable page of the parent's address space to a corresponding page of the child's address space, modern operating systems typically implement fork() using copy-on-write. With this implementation, parent and child are able to share the same page until either the parent or child write to the page, thereby minimising the number of pages which need to be copied between the address spaces and reducing memory requirements.

Additionally, there is little distinction in this article between threading implementations. The history of thread implementation has been littered with proprietary implementations from differing vendors for different platforms, and indeed, whilst the implementation of POSIX threads in C may be considered relatively cheap, the implementation of threads in Perl most certainly is not. The implementation of threads in Perl carries with it much overhead which is carried at all times within a threaded interpreter, not merely when threading is employed - For a quick example, take a look at the additional overhead required for threading in the perl_construct and perl_destruct methods in perl.c.

In short, this is a very poor discussion piece - The article has been presented with the guise that it provides an unbiased overview of the differences between threaded and fork-based concurrent programming models, yet in delivery, this article shows both poor research and a biased presentation. A better understanding of the advantages and disadvantages of these concurrent programming models I believe can be attained from some of the replies in this thread and some independent research.


In reply to Re: Why use threads over processes, or why use processes over threads? by Anonymous Monk
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.