Reflections on GIL

What is GIL?

GIL stands for Global Interpreter Lock, is a concept most common python interpreter CPython introduced. GIL is to avoid multiple threads (threads) executed simultaneously. Because memory management is not thread safe CPython, so the existence of this lock is necessary, for a short time but also can not be removed.
GIL Global is an exclusive by. There is no doubt that there is a global lock will be multi-threaded efficiency is not a small impact. Even almost equal to Python is a single-threaded program.

influences

GIL biggest problem is multi-threaded Python program and can not take advantage of multi-core CPU.
GIL will only affect those programs rely heavily on the CPU (computational), if you

How to avoid the influence

Alternative Thread with multiprocess

That the use of multiple processes instead of multiple threads. Each process has its own independent GIL, so there is no competition between GIL process.
Disadvantages: shared variables between threads easier to thread it, declare a global variable, with three lines of context wrap thread.Lock living to get. Unable to see each other while multiprocess data between processes, only through a Queue in the main Chengshen Ming, put or get re-used method of share memory.

Use other interpreters

JPython and IronPython GIL no problem, but relatively small minority. Poor functionality and performance, not a good choice.

The core of the use of other languages

If the parallel high performance computing program may be considered part of the core module written in C or other language simply

Summary, GIL will continue to exist for a longer period of time, but will continue to improve it.

Guess you like

Origin www.cnblogs.com/jkhere/p/11494511.html
GIL