查看原文:http://www.wyblog.cn/2017/02/18/python%e4%b8%ad%e7%9a%84gil%e9%97%ae%e9%a2%98/定义
GIL全称是Global Interpreter Lock,首先看看官方定义:In CPython, the global interpreter lock, or GIL, is a mutex that prevents multiple native threads from executing Python bytecodes at once. This lock is necessary mainly because CPython’s memory management is not thread-safe. (However, since the GIL exists, other features have grown to depend on the guarantees that it enforces.)定义说,GIL是多线程间的一把互斥锁,并且是一把全局锁,它保证了Cpython在内存管理上面是线程安全的。 这里要注意一点的是,官方定义开头就给了限制范围,是在CPython这个解释器下。我们知道,python存在各种各样的解释器,也就是说,在某些解释器下,其实并不存在GIL这个东西,经过查阅资料,像JPython中就不存在GIL。背景
为了发挥多核CPU性能,程序多采用多线程/多进程方式设计,这里仅关注多线程模式。多线程模式必然涉及到线程之间的通信或者同步问题,最简单粗暴的解决方式就是
Python中的GIL问题
最新推荐文章于 2023-08-04 17:28:56 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)