Question: is there any hook to catch that an object is shareable (i.e. shared() is called on it) or does the call to CLONE specify that somewhere?
Isn't that done by setting the :shared attribute on an object? i.e. marking an object as shareable is up to the caller using a module which uses Alter. AFAIK the CLONE() special subroutine has to do with package and/or class data only.
I can't seem to find any decent documentation on CLONE().
I don't know if there's much more documentation about that than what perldelta tells:
Support for the "CLONE" special subroutine had been added. With ithreads, when a new thread
is created, all Perl data is cloned, however non-Perl data cannot be cloned automatically.
In "CLONE" you can do whatever you need to do, like for example handle the cloning of non-Perl data, if necessary. "CLONE" will be executed once for every package that has it defined or inherited.
It will be called in the context of the new thread, so all modifications are made in the new area.
See perlmod
Sine the object instance data is attached to an Alter object itself, no special provision for cloning has to be taken by the Alter package; sharing those objects in threads should be as straight forward as sharing simple scalar references. I don't know for shure, but the magicext structure should automatically be cloned as well for shared objects (I haven't done much yet with threads). Whether you shoot yourself into your foot depends on what you pass into the ego() subroutine upon object construction, i.e that could be some class data reference which isn't shared or shareable.
--shmem
_($_=" "x(1<<5)."?\n".q·/)Oo. G°\ /
/\_¯/(q /
---------------------------- \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
| [reply] |