Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between concurrency and parallelism?

What is the difference between concurrency and parallelism?

Examples are appreciated.

like image 705
StackUnderflow Avatar asked Jun 26 '09 17:06

StackUnderflow


People also ask

What is the difference between concurrency parallelism and async programming?

Concurrency is having two tasks run in parallel on separate threads. However, asynchronous methods run in parallel but on the same 1 thread.

Can you have concurrency but not parallelism?

Yes, it is possible to have concurrency but not parallelism. Concurrency: Concurrency means where two different tasks or threads start working together in an overlapped time period, however, it does not mean they run at same instant. In a Concurrency, minimum two threads are to be executed for processing.

What is difference between concurrency and multithreading?

Unit of Concurrency Multitasking - Multiple tasks/processes running concurrently on a single CPU. The operating system executes these tasks by switching between them very frequently. The unit of concurrency, in this case, is a Process. Multithreading - Multiple parts of the same program running concurrently.

Is threading concurrency or parallelism?

It is possible to have parallel concurrent execution, where threads are distributed among multiple CPUs. Thus, the threads executed on the same CPU are executed concurrently, whereas threads executed on different CPUs are executed in parallel.


1 Answers

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. For example, multitasking on a single-core machine.

Parallelism is when tasks literally run at the same time, e.g., 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.

like image 107
RichieHindle Avatar answered Oct 09 '22 20:10

RichieHindle