What is the difference between concurrency and parallelism?

前端 未结 30 2668
清歌不尽
清歌不尽 2020-11-22 00:21

What is the difference between concurrency and parallelism?

Examples are appreciated.

30条回答
  •  无人及你
    2020-11-22 01:08

    I really liked this graphical representation from another answer - I think it answers the question much better than a lot of the above answers

    Parallelism vs Concurrency When two threads are running in parallel, they are both running at the same time. For example, if we have two threads, A and B, then their parallel execution would look like this:

    CPU 1: A ------------------------->

    CPU 2: B ------------------------->

    When two threads are running concurrently, their execution overlaps. Overlapping can happen in one of two ways: either the threads are executing at the same time (i.e. in parallel, as above), or their executions are being interleaved on the processor, like so:

    CPU 1: A -----------> B ----------> A -----------> B ---------->

    So, for our purposes, parallelism can be thought of as a special case of concurrency

    Source: Another answer here

    Hope that helps.

提交回复
热议问题