[Python-Dev] GIL removal question (original) (raw)

Stefan Behnel stefan_ml at behnel.de
Sat Aug 13 08:12:10 CEST 2011


Guido van Rossum, 12.08.2011 23:38:

On Fri, Aug 12, 2011 at 12:57 PM, Rene Nejsum wrote:

I think I understand the background and need for GIL. Without it Python programs would have been cluttered with lock/synchronized statements and C-extensions would be harder to write. No, sorry, the first half of this is incorrect: with or without the GIL Python code would need the same amount of fine-grained locking. (The part about C extensions is correct.) I am butting in because this is a common misunderstanding that really needs to be squashed whenever it is aired -- the GIL does not help Python code to synchronize. A thread-switch can occur between any two bytecode opcodes. Without the GIL, atomic operations (e.g. dict lookups that doesn't require evaluation of eq or hash implemented in Python) are still supposed to be atomic.

And in this context, it's worth mentioning that even C code can be bitten by the GIL being temporarily released when calling back into the interpreter. Only plain C code sequences safely keep the GIL, including many (but not all) calls to the C-API.

Stefan



More information about the Python-Dev mailing list