并行parallel和并发concurrent的区别

http://stackoverflow.com/questions/1050222/concurrency-vs-parallelism-what-is-the-difference

Concurrency is when two or more tasks can start, run, and complete in overlapping time periods. It doesn't necessarily mean they'll ever both be running at the same instant. Eg. multitasking on a single-core machine.

 

Parallelism is when tasks literally run at the same time, eg. on a multicore processor.

Quoting Sun's Multithreaded Programming Guide:

  • Concurrency: A condition that exists when at least two threads are making progress. A more generalized form of parallelism that can include time-slicing as a form of virtual parallelism.

  • Parallelism: A condition that arises when at least two threads are executing simultaneously.

 

参考:

http://www.cnblogs.com/ty408/p/5801148.html

http://www.cnblogs.com/zlcxbb/p/5754346.html

 

Concurrency vs Parallelism

https://www.codeproject.com/Articles/1267757/Concurrency-vs-Parallelism

This article will explain the difference between concurrency and parallelism. Concurrency vs parallelism has been a debated topic for a long time.

Actual Parallelism Vs Feel of Parallelism

Technical vocabulary in IT industry is sometimes very confusing and “Concurrency” and “Parallelism” are some of them. Many developers think “Concurrency and parallelism means executing at the same time” which is right 50%, but with one big difference:

  • Concurrency gives you a feel of parallelism and parallelism as the name implies is actual parallelism.

Feel of parallelism means you execute multiple tasks on the same core and the core switches context between tasks and serves them. You can also term this has time slicing / overlapping time period because your single core is just dedicating some time to one task and then some time to other.

Actual parallelism means you execute multiple tasks on multiple cores parallely.

Note: “Concurrency is a broader term and Parallelism is a subset of it”.

Mapping to the real world, the left image depicts parallelism the right image depicts concurrency.

 

Why a Feel of Parallelism and Why Not Actual?

In order to achieve actual parallelism, we need dedicated cores, separate memory and so on.
We need MORE RESOURCES.

Let’s say we want to show a progress bar for some task completed. Now we really do not want to have separate cores allocated to display the progress.

Image 3 for Concurrency vs Parallelism

We do not want PERFORMANCE here, we want that physiologically the end user feels both tasks are happening simultaneously.

We want to just beat the human eye capability of 100 FPS and give an illusion of parallelism without stressing our computer resources. But let’s say we want to process big Excel files with a million records, then yes we would love to have actual parallelism to achieve performance.

 

 

Is multi-thread belongs to concurrent or parallel?

Concurrency and parallelism are related but different concepts in computer science.

Concurrency means multiple tasks can run in overlapping time periods, but not necessarily simultaneously. In a concurrent system, a single processor can be shared among multiple tasks using techniques such as context switching or time-slicing. This is often used to improve the efficiency and responsiveness of a system.

Parallelism, on the other hand, means multiple tasks are actually executing simultaneously, typically on different processors or cores. Parallelism is used to achieve faster processing times by dividing a single large task into smaller, parallelizable subtasks that can be processed simultaneously.

Multithreading involves concurrency as it allows multiple threads (smaller subtasks of a program) to run simultaneously on a single processor through time-slicing. However, it can also involve parallelism if the program is running on a machine with multiple processors or cores, allowing the threads to run truly in parallel.

Therefore, multithreading can belong to both concurrent and parallel programming paradigms.

 

 

 

posted @ 2016-08-25 19:09  ChuckLu  阅读(1206)  评论(0编辑  收藏  举报