in reply to Re^2: What is PERL_COPY_ON_WRITE Compile Option About
in thread What is PERL_COPY_ON_WRITE Compile Option About

"Processes are threads with an attitude. Or the other way around." (I belive this is attributed to Larry, and may not be an exact quote).

Forks and threads are conceputally similar, and for the purposes of CoW, are basically the same thing.

"There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.

  • Comment on Re^3: What is PERL_COPY_ON_WRITE Compile Option About

Replies are listed 'Best First'.
Re^4: What is PERL_COPY_ON_WRITE Compile Option About
by ikegami (Patriarch) on Mar 04, 2005 at 17:49 UTC

    Similar yes, but the difference is how they share memory. Threads, by definition, share memory so that changing a variable in one thread changes the the same variable in all other threads of that process.

    Are you're saying that:

    1) CoW saves memory when creating new processes by sharing memory until a modification is made to to that part of memory, and

    2) CoW prevent threads from sharing modified variables like they normally do?

    That seems odd to me.

      *shrug* That's all a matter of implementing the thread library for your system. I haven't used Perl Threads much (too buggy for practical use), so I can't comment there, but the details of what "threads" do could change from system to system.

      "There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.

      Similar yes, but the difference is how they share memory. Threads, by definition, share memory so that changing a variable in one thread changes the the same variable in all other threads of that process.
      I'm not sure where you're getting this, but the perl threads, at least in 5.8, aren't shared by default. Every process gets it's own copy of all of the variables and such, unless you explicitly share them.

        By the CoW explanation given earlier in the thread, it would be impossible to share them beyond the point where they change, explicitely or otherwise. One would have to use some form of IPC to share data.

Re^4: What is PERL_COPY_ON_WRITE Compile Option About
by DeadPoet (Scribe) on Mar 04, 2005 at 17:44 UTC
    So does this imply that if one is not using threads, such as, when compiling perl for DBD::Oracle, then the CoW option is unnecessary? Please elaborate when one would want or need to turn on CoW.

    DeadPoet

      My advice is to just turn it on and forget about it. It's not going to hurt anything. IIRC, the OS is responsible for implementing CoW for fork(), but Perl threads are a different matter, since it looks like a single process as far as the kernel is concerned.

      "There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.