为什么Java虚拟机中没有GIL?为什么 Python 这么需要一个?
我希望有人能提供一些关于 Java 虚拟机的根本不同之处的见解,它允许它很好地实现线程而无需全局解释器锁 (GIL),而 Python 需要这样一个邪恶.
I'm hoping someone can provide some insight as to what's fundamentally different about the Java Virtual Machine that allows it to implement threads nicely without the need for a Global Interpreter Lock (GIL), while Python necessitates such an evil.
推荐答案
Python(语言)不需要 GIL(这就是为什么它可以完美地在 JVM [Jython] 和 .NET [IronPython] 上实现,并且那些实现多线程自由).CPython(流行的实现)一直使用 GIL 来简化编码(尤其是垃圾收集机制的编码)和非线程安全 C 编码库的集成(过去有很多这样的库;-).
Python (the language) doesn't need a GIL (which is why it can perfectly be implemented on JVM [Jython] and .NET [IronPython], and those implementations multithread freely). CPython (the popular implementation) has always used a GIL for ease of coding (esp. the coding of the garbage collection mechanisms) and of integration of non-thread-safe C-coded libraries (there used to be a ton of those around;-).
Unladen Swallow 项目以及其他雄心勃勃的目标,计划 用于 Python 的无 GIL 虚拟机——引用该网站的话,此外,我们打算移除 GIL 并修复 Python 中的多线程状态.我们相信这可以通过实现更复杂的 GC 系统来实现,例如 IBM 的 Recycler (Bacon et al, 2001)."
The Unladen Swallow project, among other ambitious goals, does plan a GIL-free virtual machine for Python -- to quote that site, "In addition, we intend to remove the GIL and fix the state of multithreading in Python. We believe this is possible through the implementation of a more sophisticated GC system, something like IBM's Recycler (Bacon et al, 2001)."
相关文章