今天提起GIL突然有点懵,于是小白搜遍了全网想深入了解下,硬是越看越懵,解释的真的难咽,所以个人整理了一下,希望大佬们有好的解释和用法,分享下!
GIL
- GIL(Global Interpreter Lock)全局解释器锁
- **注意:**GIL并不是Python语言的特性,它是在现实Python解释器时引用的一个概念。
首先从官方概念来看:
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.)
可以翻译为:
在cpython中,全局解释器锁(gil)是一个互斥体,它可以防止多个本机线程同时执行python字节码。这个锁是必要的,主要是因为cpython的内存管理不是线程安全的。(然而,由于gil存在&#