Python multithreading and C + + multi-Threading differences

Source: Internet
Author: User

See the forum where someone asked the Python multithreading and C + + multi-threading differences?

The warm God replied:

Python has global interpreter Lock, so ... You know.
C++11 began to be multi-threaded, using shared memory for inter-thread communication, with low-level atomic operation and memory order, and advanced lock, condition, but did not provide Message Queuing.

Then, to find the definition of Gil (Global interpreter Lock), here is a definition, as defined by the wiki. Another more popular explanation was seen on the StackOverflow:

Suppose you has multiple threads which don ' t really touch each of the other S data. Those should execute as independently as possible. If you had a "global lock" which you need to acquire in order to (say) call a function, which can end up as a bottleneck. Getting much benefit from having a multiple threads in the first place.

To put it into a real world analogy:imagine of developers working at a and only a single coffee mug. Most of the developers would spend their time waiting for coffee instead of coding.

None of this are python-specific-i don ' t know the details of what Python needed a GIL-in-the-first place. However, hopefully it's given you a better idea of the general concept.

Probably understand a basic meaning: Gil (Global interpreter Lock) will serialize thread access, so in the case of the Gil Lock, the advantages and characteristics of multithreading can not really play out. There is not even a single thread to run fast, because additional thread scheduling instructions are executed when acquire and Relea are locked. This Gil is only in the CPython, convenient loading C Extension,jython and IronPython inside is wood. So, in Python, you should use a smaller-grained lock?

Speaking of C + +, the above warm God said atomic operation, is the atomic lock, specific here has a clear explanation, atomic is a good thing .... As for the memory order, said not to understand ... Take the mutex with you honestly ...

Python multithreading and C + + multi-Threading differences

Related Article

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.