Python requires a GIL. But Jython & IronPython don't. Why?

主宰稳场 提交于 2019-12-07 05:02:36

问题


Why is it that you can run Jython and IronPython without the need for a GIL but Python (CPython) requires a GIL?


回答1:


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




回答2:


My guess, because the C libraries that CPython is built upon aren't thread-safe. Whereas Jython and IronPython are built against the Java and .Net respectively.



来源:https://stackoverflow.com/questions/3429159/python-requires-a-gil-but-jython-ironpython-dont-why

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!