[Zope-Perl] Threads

Gisle Aas gisle@ActiveState.com
20 Jun 2000 15:42:10 +0200


Last week I have been implemented the locking necessary to allow
current threads for the python/perl integration.  It basically works
the same way as the locking used for Modules/_tkinter.c in the Python
sources.  That means that we operate with two locks; a perl lock and a
python lock.  The python lock must be held when we are accessing the
python api.  The perl lock must be held when accessing the perl api.

The bad thing about this is that it does not allow two threads to
execute perl code concurrently, since there is nothing that tries to
release the perl lock until we reach python again.  This means that
the project's "Technical Requirement" about concurrency can not really
be fulfilled this way:

   http://www.zope.org/Wikis/zope-perl/FAQ
   What Are The Technical Requirements?

   1. Concurrency. Execution in the Perl code will be at least as
      concurrent as execution in Python code.

The other bad thing is that there was a need for a lot of calls to the
locking macros which makes the code longer and much harder to verify
the correctness of.

Possible improvements:

    - assume perl is thread safe (the perl-5.005 thread model) and
      eliminate the perl lock.  One problem here is that the perl
      lock was also protecting the global where we stored the
      current "PyThreadState *".  We would then need to figure
      out a way to store it somewhere else on a per thread basis.
      Other problem is that the 5.005 thread model is depreciated
      and does not really always work.

    - allocate separate perl interpreters for each thread.  This
      is the perl-5.6.0 model.  This sounds complex to me and I 
      am not sure the semantics will be correct either.  If I
      understand things correctly, each interpreter will then
      have their own module/name space.  Not really compatible
      with the python threading model.

-- 
Gisle Aas