Gil Lock Global Interpreter lock
No matter how many cores the CPU is, Python executes only one thread at a time, but does it feel concurrent? Because Python is constantly in the context of the switch.
The python thread is the native thread that invokes the operating system. Because the interface of C is called. When Python calls this thread to perform a task, the CPU needs to know the context, so it passes the context relationship to the CPU.
The requirement is 4 threads, each one thread num+1. Because each thread executes independently in parallel, the num they get is equal to 1, and the result is 2. They are also parallel, not serial, when calculating.
Each thread may be divided into different CPU cores, but only one at a time is executing. Avoid data errors, Python plus a global lock, the same time, only one thread can get this data. To modify.
Because in multi-threading, all variables are shared by all threads, so any one variable can be modified by any one thread, so the biggest danger of sharing data between threads is that multiple threads change a variable at the same time, and the content is scrambled.
Python Gil Lock