In: Computer Science
Explain the difference between concurrency and parallelism. Using these concepts, discuss how a multi-threaded application can run faster than a single-threaded application on a single-processor machine and on a multi-processor machine.
First Part:
The differences between concurrency and parallelism are the following:
Concurrency | Parallelism |
(i) It can be performed using a single CPU. | (i) It can be performed using only multiple CPUs. |
(ii) It can be defined as the process of executing and managing multiple operations at the same time. | (ii) It can be defined as the process of executing multiple operations at the same time. |
(iii) It can be performed based on context switching. | (iii) It can be performed using multiple processors. |
(iv) It increases the system throughput (number of tasks completed per unit time). | (iv) It increases the system throughput and processing speed. |
(v) It manages multiple operations simultaneously. | (v) It performs multiple operations simultaneously. |
(vi) It is non-deterministic control flow approach. | (vi) It is deterministic control flow approach. |
(vii) Debugging is more difficult. | (vii) Debugging is less difficult. |
Second Part:
Multi-threaded application can be defined as the program which have multiple threads (light-weight process) and they can be executed in the same address space. As it can have a higher degree of parallelism than a single-threaded application, so the execution speed will be faster.
In the multi-processor system, the multi-threaded application will run faster than a single-threaded application as it can have a higher degree of both concurrency and parallelism. Also, the execution will be faster than a single processor machine as the single processor machine can only achieve concurrency using context switching, but it will not be able to achieve parallelism.
Please comment in case of any doubt.
Please upvote if this helps.