Re:Data races in Python, despite the Global Interpreter Lock
by hedora on Monday February 21, 2022 @10:33PM
(#30423722)
Thanks for the link. It's too bad they exposed the GIL to C extension authors. Now people will rely on it, making it impractical to remove!
Re:Data races in Python, despite the Global Interpreter Lock
by pdonis on Monday February 21, 2022 @11:27PM
(#30423972)
> It's too bad they exposed the GIL to C extension authors.
As I understand it, yes, that has been one of the main obstacles to removing the GIL. The current way forward seems to be to make all the interpreter state per-thread, so that each thread could have a separate interpreter; this would make the GIL unnnecessary, but of course one would still need synchronization primitives like mutexes to control access to data shared between threads.
The Python documentation on threading and the GIL [1] makes it clear that the reason for the GIL is to make operations on Python objects inside the interpreter thread-safe, by ensuring that the C structures that store the states of Python objects can only be mutated by one thread at a time. All of those C-level operations happen "inside" a single bytecode. Python operations that require multiple bytecodes do not have any of the same guarantees.
[1] https://docs.python.org/3/c-api/init.html#thread-state-and-t...