The topics in this article are as follows:
1. The difference between parallel programming and multithreaded programming.
2. Advantages and disadvantages of parallel programming technology
3. When to use parallel programming
1. The difference between parallel programming and multithreaded programming.
1.1 Parallel programming.
Now with the popularity of multi-core computers, parallel programming technology, that is, multi-core programming technology is gradually called the development of the mainstream. For this reason, "parallel programming" is introduced in. NET 4. The Library and classes for some of the columns in. NET 4 provide support for parallel programming, such as Task Parallel Library,parallel LINQ.
In fact, in. NET 1.0, there are some implementations of parallel programming techniques---multi-line threading technology. The biggest problem with multithreading is that it is difficult to use and manage. In the use of multithreading, because of its complexity, it is often used to distract us with multithreading. And our original purpose was obscured.
1.2 Comparison differences
The underlying mechanism for programming in. NET 4 is actually based on multithreading. But the big difference is that it's more convenient to have parallel programming in. NET 4.
In the traditional programming model, programmers are responsible for creating threads, assigning tasks to threads, and managing threads. An image metaphor: You have a group of soldiers, and then you give them an order, and then you have to keep an eye on your soldiers and make sure that they act on your terms. (Very tired!) )
Parallel programming in. NET 4 is based on the task Parallel Library (later, TPL). In TPL, the most basic execution unit is task (Chinese can be understood as "task"), and a task represents an action you want to perform. You can define a TASK,TPL for each action you want to perform to create threads to execute the tasks you define and manage threads. TPL is task-oriented, automatic, and traditional multithreading is manual.
The task mechanism allows us to focus on the problem we are trying to solve. If the previous multithreaded technology had enabled us to give up some of the use of parallel programming, the new parallel programming technology in. NET 4 would allow us to re-establish confidence.
Although there is a new parallel technology, but the traditional multithreading technology is very useful. When we execute multiple tasks while using the parallel technology in the TPL, we do not have to care about the underlying create threads, manage threads, and so on.
2. Advantages and disadvantages of parallel programming technology
The biggest advantage of using parallel technology is that it improves the performance of the system. The parallel processing process is usually this: a task to be performed is split into a number of small parts, and these small portions are executed on different processors (which can be multi-core or many computers). Because many of these small parts are executed at the same time, they are called "parallelism".