New Python proposal: remove the global interpreter lock GIL, liberate multi-threading performance

According to the Python Foundation blog , developer Sam Gross brought a new proposal at the 2022 Python Language Summit: to completely remove the CPython interpreter's GIL-global interpreter lock , allowing Python programs to achieve faster performance -- especially Multithreaded program. 

There are several versions of Python, including the JVM, .NET CLR interpreter, and compiler, but the core implementation of the language is still the CPython interpreter. Since CPython's memory management is not thread-safe, CPython's GIL (Global Interpreter Lock) is designed to prevent race conditions and ensure thread-safety. The GIL is a mutex that allows only one thread to hold control of the Python interpreter, thus protecting access to Python objects and preventing multiple threads from executing Python bytecode at the same time. 

But in hindsight, the GIL was not ideal because it prevented multithreaded CPython programs from taking full advantage of the performance of multicore processors. But since the GIL has been around for a long time, many official and unofficial Python packages and modules are deeply integrated with the GIL module, and the work of removing the GIL functionality has become a long way to go. Previously, developer Larry Hastings attempted to complete the removal of CPython GIL functionality in his "Gilectomy" (GIL Removal Surgery) project, but the project failed because it made single-threaded Python code significantly slower.  

The Python Language Summit brought another project "nogil" , which was hosted by Meta developer Sam Gross. It is not difficult to see from the project name that this is also a project focused on removing the GIL. Referring to the failure of the Gilectomy project, Sam Gross realized that if Python was to work effectively without the GIL, new locks would need to be added to ensure that it was still thread-safe. However, adding new locks to existing code can be very difficult, as new locks can cause significant performance degradation in some areas. 

According to the Python Foundation, Gross will invent a new type of lock, a "more auspicious" lock. If all goes well, this new lock is likely to debut in Python 3.12, as Gross' proposal was to "introduce a new compiler flag in Python 3.12 that will disable the GIL."

Guess you like

Origin www.oschina.net/news/196247/remove-gil-from-cpython