Python需要一个GIL.但是Jython& IronPython不会.为什么? [英] Python requires a GIL. But Jython & IronPython don't. Why?
问题描述
为什么无需GIL即可运行Jython和IronPython,而Python(CPython)却需要GIL?
Why is it that you can run Jython and IronPython without the need for a GIL but Python (CPython) requires a GIL?
推荐答案
解释器的部分不是线程安全的,尽管主要是因为通过大量使用锁使它们全部变为线程安全,这会极大地减慢单线程
Parts of the Interpreter aren't threadsafe, though mostly because making them all threadsafe by massive lock usage would slow single-threaded extremely (source). This seems to be related to the CPython garbage collector using reference counting (the JVM and CLR don't, and therefore don't need to lock/release a reference count every time). But even if someone thought of an acceptable solution and implemented it, third party libraries would still have the same problems.
Note that extensions written in C can in fact get rid of the GIL: http://docs.python.org/c-api/init.html#thread-state-and-the-global-interpreter-lock
这篇关于Python需要一个GIL.但是Jython& IronPython不会.为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!