Python 的 GIL 是什麼?

前言 在面試的時候被問到 GIL,雖然我是直接回答說我看不懂,但是仔細想想上一次看也是快一年前了,於是想趁報到前再來挑戰一次 GIL 主要會分兩個部分來講 GIL 是什麼 GIL 會造成什麼影響 如何避免 GIL 造成的問題 總結 GIL 是什麼? In CPython, the global interpreter lock, or GIL, is a mutex that protects access to Python objects, preventing multiple threads from executing Python bytecodes at once. The GIL prevents race conditions and ensures thread safety. A nice explanation of how the Python GIL helps in these areas can be found here. In short, this mutex is necessary mainly because CPython’s memory management is not thread-safe. ...

July 11, 2021 · 2 min · Set Mao