At 12:05 PM -0800 1/4/04, Jeff Clites wrote:
On Jan 4, 2004, at 5:47 AM, Leopold Toetsch wrote:

Elizabeth Mattijsen <[EMAIL PROTECTED]> wrote:

When you use an external library in Perl, such as e.g. libxml, you
have Perl data-structures and libxml data-structures.  The Perl
data-structures contain pointers to the libxml data-structures.

In comes the starting of an ithread and Perl clones all of the Perl
data-structures.  But it copies _only_ does things it knows about.
And thus leaves the pointers to the libxml data-structures untouched.
Now you have 2 Perl data-structures that point to the _same_ libxml
data-structures.  Voila, instant sharing.

I see. Our library loading code should take care of that. On thread creation we call again the _init code, so that the external lib can prepare itself to be used from multiple threads. But don't ask me about details ;)

But I think we'll never be able to make this work as the user would initially expect. For instance if we have a DBI implementation, and some PMC is holding an external reference to a database cursor for an open transaction, then we can't properly duplicate the necessary state to make the copy of the PMC work correctly (that is, independently). (And I'm not saying just that we can't do it from within parrot, I'm saying the native database libraries can't do this.)

And don't forget the libraries that are picky about which thread calls into them -- there are some that require that the thread that created the handle for the library be the thread that calls into the library with that handle. (Though luckily those are pretty rare) And of course the non-reentrant libraries that require a global library lock for all calls otherwise the library state gets corrupted.


Aren't threads fun? :)
--
                                        Dan

--------------------------------------"it's like this"-------------------
Dan Sugalski                          even samurai
[EMAIL PROTECTED]                         have teddy bears and even
                                      teddy bears get drunk

Reply via email to