in reply to Re: Threads or Forking?
in thread Threads or Forking?

On modern OSses, you know, those OSses modern enough to support threads, a fork copies the memory space of program as COW (Copy On Write) - space for copies of the pages in memory are claimed, but the pages aren't copied yet. They will only be copied if either the parent, or the child writes to that page.

Replies are listed 'Best First'.
Re^3: Threads or Forking?
by BrowserUk (Patriarch) on Jul 30, 2005 at 01:28 UTC

    But remember this. Read-only at the Perl level does not mean read-only at the C-level.

    With COW, If you use a read-only variable, that is a number read from a file, in a calculation, the IV or NV field of that variable will be written to and the 4k page containing that scalar will have to be copied.

    If you take a reference to a read-only scalar, the flags field in that scalar will be updated and the 4k page will be copied.

    And there are a dozen or so other flags and fields that can be modifed as a result of Perl-level read accesses to a scalar, hash or array that will cause pages to be copied.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.