
多线程和并行计算有什么关系和区别
2017-12-20 · 知道合伙人数码行家

知道合伙人数码行家
向TA提问 私信TA

并行是将问题分解交给不同的CPU内核去处理。
而多线程是串行,使用时间分片。
很明显并行比多线程具有更高的CPU利用率,因此效率相对更高。来自MSDN:(TPL - Task Parallel Library)
The TPL scales the degree of concurrency dynamically to most efficiently use all the processors that are available. In addition, the TPL handles the partitioning of the work, the scheduling of threads on the ThreadPool, cancellation support, state management, and other low-level details. By using TPL, you can maximize the performance of your code while focusing on the work that your program is designed to accomplish.
从MSDN的解释可以看出,TPL也包含了将task分配到多线程的过程,但是它比MT多了更多细节的东西,比如分解work,状态管理,取消机制和更多的low-level details,这些都是简单的多线程做不到的(除非你自己实现这一套类似的东西)。