Concurrency vs. Parallelism: The Difference
最近在看一些并行编程相关的内容,经常碰到两个单词:concurrency和parallelism。一直没有搞明白这两个词到底啥区别,总感觉是一样的。所以,google是必须的。不过不管是Stack Overflow还是其他搜索结果,个人总觉得说明得不够让人好理解。今天看书,算是看到一份个人觉得非常完整的说明:
Concurrency is a concept related to multitasking and asynchronous input-output (I/O). It usually refers to the existence of multiple threads of execution that may each get a slice of time to execute before being preempted by another thread, which also gets a slice of time. Concurrency is necessary in order for a program to react to external stimuli such as user input, devices, and sensors. Operating systems and games, by their very nature, are concurrent, even on one core.
With parallelism, concurrent threads execute at the same time on multiple cores. Parallel programming focuses on improving the performance of applications that use a lot of processor power and are not constantly interrupted when multiple cores are available.
The goals of concurrency and parallelism are distinct. The main goal of concurrency is to reduce latency by never allowing long periods of time to go by without at least some computation being performed by each unblocked thread. In other words, the goal of concurrency is to prevent thread starvation.
Concurrency is required operationally. For example, an operating system with a graphical user interface must support concurrency if more than one window at a time can update its display area on a single-core computer. Parallelism, on the other hand, is only about throughput. It’s an optimization, not a functional requirement. Its goal is to maximize processor usage across all available cores; to do this, it uses scheduling algorithms that are not preemptive, such as algorithms that process queues or stacks of work to be done.
posted on 2013-01-29 19:17 wpcockroach 阅读(918) 评论(5) 编辑 收藏 举报