Concurrency(并发)和Parallelism(并行)的解释

今天看到一个对Concurrency(并发)和Parallelism(并行)这两个术语的一个解释,感觉很精确。记录在此,以供日后查阅(原文在这里):

Concurrency and parallelism are two related but distinct concepts.

Concurrency means, essentially, that task A and task B both need to happen independently of each other, and A starts running, and then B starts before A is finished.

There are various different ways of accomplishing concurrency. One of them is parallelism--having multiple CPUs working on the different tasks at the same time. But that's not the only way. Another is by task switching, which works like this: Task A works up to a certain point, then the CPU working on it stops and switches over to task B, works on it for a while, and then switches back to task A. If the time slices are small enough, it may appear to the user that both things are being run in parallel, even though they're actually being processed in serial by a multitasking CPU.  

Concurrency(并发)是指系统上的多个task(任务)之间由于没有任何依赖关系,所以可以同时运行。以两个taskAB),两核CPUAB)系统为例,如果在一个时间点上,task ACPU A上运行,而task BCPU B上运行,我们就可以称这两个taskParallelism(并行)运行的。对单核CPU来说,由于在一个时间点上只能执行一个task,所以这两个task只能是Sequential(串行)运行的。

一句话总结,Concurrency(并发)描述了task之间的逻辑关系(能否同时运行),而Parallelism则描述了task运行时的真正状态(是否真的在同时运行)。

发表评论

邮箱地址不会被公开。 必填项已用*标注

This site uses Akismet to reduce spam. Learn how your comment data is processed.