Jython, GILs and object locking.

Alan Kennedy alanmk at hotmail.com
Thu Oct 16 13:16:49 EDT 2003


[Daniel Dittmar]
> Reference counters are being changed almost everywhere in Python,
> when tuples are created, when parameters are passed to a method
> etc. All this will get slower because access to the counters has
> to be synchronized.
> 
> One could try to remove reference counting along with the GIL, but
> that has other repercussions, some for extension writers, some for
> the language CPython (Jython has already these problems).

Daniel,

You are obviously right in relation to reference counters and
synchronisation in cpython, i.e. without the GIL, there must be
synchronisation of access to individual objects and their reference
counters. And that applies to all objects, not just static objects
like PyNone, etc.

However, I don't understand what problems jython "already has" in
relation to removal of the GIL: jython doesn't have a GIL.

My understanding is that jython objects are really java objects, and
as such they are managed by the platform, i.e. the JVM, in terms of
allocation and garbage collection. And the underlying JVM may be using
one of a number of garbage collection strategies, not necessarily
reference counting.

If there are any critical sections of code requiring that only one
thread at a time be in the section, they are declared as
"synchronized" in the java source for jython. A good example of this
is the PyStringMap class, which implements python dictionaries where
the keys are always strings. Every method of that class that reads or
writes the dictionary is marked as "synchronized", which means that
all accesses to individual PyStringMap instances from different
threads is guarded by a separate lock on each instance.

So jython already is what some people want cpython to be: a GILless
python, with multiple threads being able to run python code
simultaneously (actually, not pseudo) when multiple processors are
present, and with synchronisation locks being maintained at an
individual object level. 

Writing "extensions" for jython, in java, is simplicity itself,
because the integration of the two languages is so seamless (I often
think of writing jython as writing java without the tortuous syntax
;-)

If you have the time, I'd like to know what problems you mean. Apart
from the small time delays involved in the finer-grained locking, I
can't see any in relation to jython.

regards,

-- 
alan kennedy
-----------------------------------------------------
check http headers here: http://xhaus.com/headers
email alan:              http://xhaus.com/mailto/alan




More information about the Python-list mailing list