The GIL (Global Interpreter Lock) understood

GIL lock, global interpreter lock, the role is to limit multiple threads execute simultaneously, in the same time to ensure that only one thread execution.

Non-independent threads, so the threads in the same process is data sharing, when each thread to access data resources will be competing state, that data may be occupied simultaneously by multiple threads, resulting in data confusion, this thread is unsafe.

Therefore, the introduction of exclusive (chi) lock, to ensure a certain critical code, data can only be fully shared by a thread from beginning to end, but this has a fatal problem, deadlock.

Deadlock: several sub-thread system resource contention, are waiting for the other to lift the state of occupation of a part of the resources, the results oh who are unwilling to unlock, waiting for each other, the program can not execute it, this is a deadlock.

Knowledge extension

GIL Due to historical reasons, the introduction of a turtle t-GIL in python to ensure that every process at any time only one thread to execute acquiring a lock and access to resources, avoid the multi-threaded execution, to ensure the security thread.

There are two voices for GIL A GIL an interview, one is not accepted GIL, removed from the python

A reception GIL, since the python appeared, followed by too many modules are used to write python's GIL, upon removal of the GIL, these modules need to be rewritten, too costly

Two GIL remove, remove the GIL in order to take advantage of multi-core processors can speed up the implementation of multi-threaded programs, to achieve true multi-threaded

solution

1, for the interpreter GIL has only cpython can change jpython

2, for multi-process less thread

3, using C language extensions
---------------------
Author: Gray Village Primary School --python Chen
Source: CSDN
Original: https: //blog.csdn. net / xiaochendefendoushi / article / details / 81074826
copyright: This article is a blogger original article, reproduced, please attach Bowen link!

Guess you like

Origin www.cnblogs.com/abella/p/11081433.html