Python Gil Lock

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.