Why GIL? (was Re: what's the point of rpython?)

Carl Banks pavlovevidence at gmail.com
Fri Jan 23 07:40:10 CET 2009


On Jan 22, 10:15 pm, Paul Rubin <http://phr...@NOSPAM.invalid> wrote:
> Carl Banks <pavlovevide... at gmail.com> writes:
> > 3. If you are going to use the low-level API on a mutable object, or
> > are going to access the object structure directly, you need to acquire
> > the object's mutex. Macros such as Py_LOCK(), Py_LOCK2(), Py_UNLOCK()
> > would be provided.
>
> You mean every time you access a list or dictionary or class instance,
> you have to acquire a mutex?  That sounds like a horrible slowdown.

Yes, and it's never going to happen in CPython any other way.  It's
considered a bug if Python code can segfault the interpreter; all
runtime errors are supposed to raise exceptions.  The only way to
ensure that won't happen is to make sure that only one thread can can
access the internals of a mutable object at a time.

BTW, class instances are usually immutable and thus don't require a
mutex in the system I described.


Carl Banks



More information about the Python-list mailing list