There is one more problem with objects that store (or point to) 
something off Perl symbol table.

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.

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.

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]>

Reply via email to