From:                   Garry Williams <[EMAIL PROTECTED]>
> On Sat, Nov 10, 2001 at 03:58:04PM -0800, Marcia Magna wrote:
> 
> > I have a program that needs to fork. The child process creates
> > values in a hash that must be seen by the parent process.
> > 
> > Is there anyway to do that ?
> 
> Short answer: No.  
> 
> When a process fork()s, a new process is created.  

Depends. On windows you only get a new thread, not a new 
process. And only if you exec() later a new process is created. 
This should not make much difference usualy ... except that 
currently not everything is thread safe so if you don't exec() and 
continue running the same code in both threads your script can 
crash. Plus you have to be carefull with some modules that keep 
some data outside the Perl space, since that data is NOT copied 
when you fork and may get deleted when one of the thread finishes.

> That means there is
> now a *copy* of all of the memory in the original process now in the
> new process.  So all Perl variables are *copied* to the new process.
> Since the new process is using a copy, no changes in the child process
> can be "seen" by the parent.  

Same in the thread "emulation" of fork(). Except if you use 
Thread::Shared. Not sure though what data types are supported at 
the moment, plus you'd have to install bleadperl (the development 
version of Perl)

> Long answer: 
> 
> Take a look at the perlipc manual page for various ways for processes
> to communicate with each other (including shared memory on *some*
> systems).  It's likely that there is another way to partition or
> factor your problem that does not involve complex inter-process
> communication.  

Yes, there are modules on CPAN that implement hashes shared 
between processes (so they might work with multiple threads as 
well. I did not try.)

Jenda

=========== [EMAIL PROTECTED] == http://Jenda.Krynicky.cz ==========
There is a reason for living. There must be. I've seen it somewhere.
It's just that in the mess on my table ... and in my brain.
I can't find it.
                                        --- me

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to