PyPy vs Cpython, will either one drop GIL and support POSIX Threads?

Given that the GIL limits pythons ability to support true threads, is it possible to strip it out of current python implementations so that the language can finally support true multithreading. Furthermore, assuming that the GIL is dropped, would that mean that multi-core threading would finally come to scripting/interpreted languages such as Python and Ruby?


Your question is flawed. Python supports threads just fine. In fact, when you create a thread in a Python program running under a *nix it likely creates exactly one additional pthreads thread, no questions asked. The only restriction is that Python code won't run in parallel (but it does run concurrently, interleaved, etc.). Code that's not under the GIL, such as almost everything that does I/O, doesn't prevent other threads from running Python code.

As for removing the GIL... it's hard. Like, really really hard . You and me can just assume it's infeasible (hey, at least we'll be pleasantly surprised if some superhuman does succeed). Other implementations (Jython, IronPython) don't have a GIL, but their approaches aren't practical for CPython (and not easy for PyPy either, from what I hear) and they can't exactly replace CPython as they lag behind a lot, don't support C extensions, are less portable to more exotic platforms, etc.

That said, some PyPy developers are working on an STM solution (latest update) that would free PyPy from the GIL. CPython on the other hand? I don't think there's a chance, even with STM, especially when potential ABI and API breakage is taken into account.

链接地址: http://www.djcxy.com/p/86468.html

上一篇: 受GIL影响的线程化Python

下一篇: PyPy vs Cpython,会不会放弃GIL并支持POSIX线程?