20191031: GIL Global Interpreter Lock

20191031: GIL Global Interpreter Lock

Summary of the GIL Global Interpreter Lock personal understanding

GIl global characteristics explained lock, Python language itself is not, but a characteristic C Python Python language interpreter underlayer. In other interpreter is not the concept, such jpython and pypy.
What is the interpreter of it? That is our own language is written in Python language computer visualization is not able to understand and execute, the computer itself, it is only able to identify a binary signal. This binary signal that he is powered on and off by an analog circuit 01 to be simulated.
Based on the above concept, then each python file you want to be executed, you need an interpreter to interpret Python code, which is compiled of course.
Python memory management depend on gc, Gc itself also needs a thread to be executed, that example, I want to recycle trash Well, I also have to find a thread system inside the garbage. That it, that is to say a python code execution in memory based on such a scene in memory at the same time there will be at least two threads are running! So there is a scenario is as follows:
In the case of an unlocked, when the garbage collector found a thread as a variable x assigned reference number 0, garbage collection thread is ready to reclaim the memory space of this variable, this time Cpu suddenly switch to another a thread, for example, in another thread inside at this time and used the address reference to x, then the time slice to the future, the CPU switches again to the garbage collection thread, and then thread garbage collection to reclaim memory space to continue this x, and then switch the CPU again a reference to the time of this thread x, find x has been recovered, it will lead to confusion resources. Therefore, we need a global explanation locked inside this allocation of memory and reclaims the memory lock operation, after you add a lock garbage collection thread to recovery when he discovered ah, the recovery can not be locked.

Guess you like

Origin www.cnblogs.com/hyj691001/p/11773282.html