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.

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.

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.


Liz

Reply via email to