At 22:38 -0800 12/3/03, Stas Bekman wrote:
In fact if it didn't have a problem with destroy (which is possible to workaround in the destroy method by tracking who created the original object), I'd say that this is a Copy-On-Write situation, as long as nobody modifies the object it's perfectly find to have several objects pointing to the same C structs from different threads. If you ever create an object in the parent perl and never modifying it, it'll be much more efficient, than blindly reconstruct all variables. Only when the object wants to be modified, it will be then reconstructed and modified, without affecting any other threads. You don't even need mutexes for this to work. This could be made into yet another handy reusable module, I'm sure Liz will post an announcement in the next few minutes ;)
It's already there... ;-)
Actually, this is the other thing that Thread::Bless does: do _not_ call DESTROY on objects that have been cloned, only call DESTROY on the original object.
So, _if_ you have blessed objects and _if_ you're fine with only DESTROYing on the original object (and have the cloned objects share whatevers C structures they have),.then the only thing you need is add "use Thread::Bless" to your module's code and Thread::Bless will automagically only have DESTROY methods called on original objects.
Right, and should be really called Thread::BlessReadOnly then.
Alternately, again _if_ you have blessed objects and you _do_ need to fix objects up after they have been cloned (hence the name "fixup" for this functionality), you can have a method of your own devise called on each instantiated object automagically after Perl has cloned it.
That's incomplete, because you won't call DESTROY on those fixedup/possessed objects. I suppose that you should check whether the user of your module provides the fixup callback and if it does DESTROY all objects (or make it configurable).
However, this only works on blessed objects, not on unblessed ones. On the other hand, you could decide to bless your SV to a special class just to get this functionality.
You mean double bless? My objects are already "blessed", but they don't use bless:
sv_setref_pv(ST(0), "Example::CLONE", (void*)RETVAL);
How about making your module more flexible and in addition to the overriden bless function provide a new_fixup methods, so one can choose to run new_fixup on already "blessed"/sv_setref_pv'ed object to store a weak copy of it? this can be called from the normal new().
So the only remaining nice-to-have issue is to do COW for a better performance.
__________________________________________________________________ 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
