How can an interpretive language avoid using Global Interpreter lock (GIL)?

CPython uses a Global Interpreter Lock. Linux has removed all traces of the Big Kernel Lock. What is the alternative to these locks? How can a system make full use of a truly multi-core or multi-processor system without grinding everything to a halt?


A GIL wouldn't be necessary if python used a more advanced Garbage Collector like IBM's Recycler instated of a primitive reference counting method. This is something that Unladen Swallow is doing to improve the performance of python. A more prommising answer is Stackless Python, which uses its own micro-thread implementation instead of relying on the operating system like traditional CPython.


The GIL is process specific, so you can get around it by launching several Python processes. The multiprocessing module provides an easy-to-use API for this.

Another way is to use C-extensions (or write your own) which release the GIL while doing the kind of data processing you need.


Simple. Have no mutable state, much like Haskell and other functional programming languages do. Since nothing in memory needs to be changed, no global lock is ever needed.

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

上一篇: Python GIL和线程同步

下一篇: 解释性语言如何避免使用全局解释器锁(GIL)?