Python GIL(Global Interpreter Lock)
about Global Interpreter Lock in python.
korean version
- what is the GIL?
- Global Interpreter Lock is a mutex that allows only one thread to hold the control of the python interpreter
- how does python works?
- interpreter is loaded in memory
- python code is run through interpreter
- python’s memory management
- python object’s creation and destruction is managed through reference count
- refcount is attribute that object have and keeps track of the number of refrence that point to object
- when refcount reaches to zero, the memory occupied by the object is released.
- why use GIL?
-
this reference count variable needed protection from race conditions where two threads increase or decrease its value simultaneously, so always lock when increase or decrease refcount.
but python is everythng consist of object so inefficient.Therefore python is using GIL.
-
- advance
- generally using multiprocessing modules about asynchronous problem.
but there is somthing special about CPU usage. this part will be updated later.
- generally using multiprocessing modules about asynchronous problem.
Leave a comment