Posted on 2007-10-29 15:18:03-07 by jdhedden in response to 6344
Re: Problem with shared objects
> I believe that this happens during the copying of the object
> into the global stash inside of shared.xs. I have no
> experience with xs code, so I'm not sure, but it looks to me
> that only a thin copy of the object was done, not a deep as
> needed.

The comments in the XS file explain how threads::shared work:
/* * Shared variables are implemented by a scheme similar to tieing. * Each thread has a proxy SV with attached magic -- "private SVs" -- * which all point to a single SV in a separate shared interpreter * (PL_sharedsv_space) -- "shared SVs". * * The shared SV holds the variable's true values, and its state is * copied between the shared and private SVs with the usual * mg_get()/mg_set() arrangement. * * ...
The problem with storing shared objects in shared structures involves the destruction of the 'proxy SVs': When the proxy SV is destroyed, the object's DESTROY subroutine is called even though the actual object is not being destroyed.

Here's my ignorant guess at what a solution to this might entail:
1. Modifications to the interpreter to not call DESTROY for proxy SVs.
2. Tracking of the proxy SVs and modifications to the interpreter to call DESTROY when there are no more proxy SVs for a shared object.
Direct Responses: 6420 | Write a response
Perl Weekly newsletter
A free weekly newsletter for people who are busy to read all the blogs. click here to check it out.