SPUG: references, subroutines, fork
Colin Meyer
cmeyer at helvella.org
Thu Nov 29 15:24:05 CST 2001
Hi, Benjamin,
On Thu, Nov 29, 2001 at 12:25:40PM -0800, Benjamin Franks wrote:
> I pass a subroutine a reference to a array. The subroutine forks off a
> child and then makes use of the reference to the hash. However, in the
> parent branch of the fork, I empty/delete the underlying array
> elements. Even if I put the child to sleep until well after the parent
> has deleted the array, I can still access the data the reference use
> to point to. I would have imagined if you destroy the underlying data
> the reference would reflect that change. What's happening...how does
> perl handle this situation?
When a process forks, the child gets a unique copy of the parent's
memory. Thus when the parent modifies a variable, the child's copy of
that same variable doesn't get modified. (Actually, your operating
system uses "copy-on-write" memory handling so that the processes'
memory remain shared until one of them writes to it.)
Thanks for posting code!
Have fun,
-C.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
Subscriptions; Email to majordomo at pm.org: ACTION LIST EMAIL
Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
For daily traffic, use spug-list for LIST ; for weekly, spug-list-digest
Seattle Perl Users Group (SPUG) Home Page: http://zipcon.net/spug/
More information about the spug-list
mailing list