Umm,
post_clone_reconstruct()
But rather than use plain SvIV's in the application why not use
SV's with '~' magic where the mg_ptr (if memory serves) is a pointer
to an SV. Perl knows it's a pointer to an SV so when the interpreter
is cloned the clone gets it's own copy of the pointed-to SV as well.
Or am I missing something?
Tim.
On Wed, Dec 03, 2003 at 12:06:20PM -0800, Stas Bekman wrote:
> Perl doesn't know how to handle the special variables that contain a
> pointer to the C struct, because they aren't special to Perl. All Perl sees
> is something like 0x832cf08 in a variable's $y IV slot, which is exactly
> the same as 5 in the previous example. So what it does, is cloning that $y,
> including its IV slot. In the case of $x containing 5, two threads
> manipulating that variable don't affect each other. However in the case of
> $y, two threads are now operating on the same C struct pointer. Several
> problems emerge:
>
> 1) you now to need to serialize the access to this variable or make the XS
> code thread-safe
>
> 2) When $y goes out of scope, perl will call DESTROY which will try to free
> the memory allocated by the C struct. So the first threads successfully
> free()s the memory. Now the second thread is in trouble as it'll try to
> work with memory that was deallocated. All kind of segfaults and hangs kick
> in.
>
> Obviously there is a solution to this problem. Enter the magic CLONE
> function called when a new thread is spawned (perl_clone is called). If a
> package defines this function, perl will call it. When CLONE is called Perl
> has already cloned $y. So what you need to do is to go and change $y's guts
> to point to a new C struct, initialized from the original C struct. But
> without changing $y, i.e. it's external appearance must not change. Only
> the IV slot needs to be changed. So here is where my question comes into
> the picture. How to call that method that will substitute the IV slot
> without changing the object. It's going to be used by many XS modules so
> we'd better choose a good name for it so we can all talk about the same
> method.
>
> I chose the name 'possess' as if the object 'being possessed by some evil
> spirit'. Remember that the external object must stay the same (since it
> lives in the user's space, e.g. script and we can't touch it).
>
> Liz wrote a module Thread::Bless which provides a framework for this issue,
> and she called this method 'fixup'.
>
> Now that hopefully you understand the problem and what the method is trying
> to achieve, Liz and I are trying to get more ideas from you.
>
> BTW, if you want to understand the issue in more details, I've written
> Example::CLONE which is a simple interface to C struct with a few accessors:
> http://apache.org/~stas/Example-CLONE-0.01.tar.gz
> Once it's polished you will find it in the perlthreads manpage, and I may
> post an article on the topic...
>
> __________________________________________________________________
> Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
> http://stason.org/ mod_perl Guide ---> http://perl.apache.org
> mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com
> http://modperlbook.org http://apache.org http://ticketmaster.com
>