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