c++11 parallel, concurrent, and multithreaded programming

Source: Internet
Author: User

First, we first understand the differences between concurrency and parallelism.

You eat half of the meal, the phone is coming, you have to eat until after the end of the answer, which means that you do not support concurrency and do not support parallelism.

You eat half of the meal, the phone came, you stopped to pick up the phone, and then continue to eat, which shows that you support concurrency.
You eat half of the meal, the phone is coming, you are on the phone while eating, it shows that you support parallel.

The key to concurrency is that you have the ability to handle multiple tasks, not necessarily at the same time.
The key to parallelism is that you have the ability to handle multiple tasks at the same time.

So I think the key point is: "At the same time."

As shown above, concurrency can be understood to occur within the same time period, while parallelism means that two events occur in parallel, that is, simultaneous.

We know that JavaScript does not support multithreading, and Python, PHP, Java and so on are multi-threaded, as well, C + + is also support multithreaded programming.

In C++11, the following header file is used to support multithreaded programming:

    • <atomic>: The header file declares two classes, namely Std::atomic and St::atomic_flag.
    • <thread>: The header file mainly declares the Std::thread class.
    • <mutex>: Chinese is the meaning of mutual exclusion. The header file primarily declares classes related to mutexes (mutexes), such as Std::lock_gruad and Std::unique_lock, as well as other types and functions.
    • <condition_variable>: The header file declares the classes associated with the condition variable, including std::condition_variable and Std::condition_variable_any.
    • <future>: This header file mainly declares std::p romise,std::p ackage_task Two provider classes, and Std::future and Std::shared_future classes, There are other types and functions associated with it, and the Std::async () function is declared in this header file.

  

  

c++11 parallel, concurrent, and multithreaded programming

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.