01-06-03 01.22, skrev Jenda Krynicky p� [EMAIL PROTECTED] f�ljande:
> There is one more problem with objects that store (or point to)
> something off Perl symbol table.
Indeed there is, therefore I proposed a CLONE callback on all blessed
objects when perl_clone is called. I haven't gotten around implmenting it.
> If one of your threads finishes it calls the objects DESTROY(), which
> will free the handles/memory/whatever so the other clones of that
> object will start to point to nowhere. Which will be a problem no
> matter how threadsafe is the module.
The object should clone itself, and if it doesn't it should increase it's
own interpreter count so even if it DESTROYS it shouldn't destroy the
underlaying object. (I do this with ithread::shared stuff).
> Say you use Win32::Semaphore to control the number of subprocesses
> created at a givven time. You have to create the Win32::Semaphore
> object in the mother before you start to fork out the children, but
> the first child to finish destroys the parent's object.
>
> The only way to implement this that I found was to
>
> bless $sem, "NonexistentPackage"; undef $sem;
> $sem = Win32::Semaphore->open($name);
>
> in the children.
Yes this works, but it is an ugly hack :). I also use kill 9,$$ if I want to
quit without calling destroy. (there is also POSIX::_exit(0));
> Here is a longer explanation with examples :
> http://Jenda.Krynicky.cz/iThreads.html
>
> Of course if the module knows about the cloning and ensures
> everything is OK with multithreading this will become unnecessary.
>
>
> BTW: I think it would be nice if there was a way to mark an object so
> that it is not cloned at all. The reference in children will be
> undefined and the father will have the only copy of the object. Or
> maybe the whole class should be marked as uncloneable.
>
> And iThread.pm could even mark the classes it knows are not
> cloneable.
>
> If the module is updated so that it clones the external state
> properly, it has to be able to tell iThread.pm it is safe now.
>
> What do you think?
>
> Jenda
>
> == [EMAIL PROTECTED] == http://Jenda.Krynicky.cz ==
> : What do people think?
> What, do people think? :-)
> -- Larry Wall in <[EMAIL PROTECTED]>
>
If an object is implmented in perl it can declare itself shared. Are you
also gvs can be shared by using the :shared flag. But you want to declare an
object to become void in the clone. That is rather scary ain't it, it could
pull out lots of problems for complex structures.
Otoh an object could implment this by nulling its copy when the CLONE
callback is called. Then it also is up to the object to know if something
can be shared or not.
There is a module called IThread::Safe which implments some unsafe
perlfunctions (unsafe on non safe c libs) with mutexes around em. You
suggest we should have a list of all threadsafe/nonthreadsafe perl libraries
in there? Won't that be maintaince hell for us to update?
Artur