Threading vs Parallelism, how do they differ?

前端 未结 9 2142
后悔当初
后悔当初 2020-12-04 07:15

What is the difference between threading and parallelism?

Which one has advantage over the other?

9条回答
  •  我在风中等你
    2020-12-04 07:58

    How do you define "parallelism"? Multithreading is a concrete implementation of the concept of parallel program execution.

    The article RichardOD linked to seems to be mainly concerned with whether threads are actually executed in parallel on a concrete machine.

    However, your question seems to see multithreading and parallelism as opposites. Do you perhaps mean programs that use multiple processes rather than multiple threads? If so, the differences are:

    • Threads are much cheaper to create than processes. This is why using threads rather than processes resulted in a huge speedup in web applications - this was called "FastCGI".
    • Multiple threads on the same machine have access to shared memory. This makes communication between threads much easier, but also very dangerous (it's easy to create bugs like race conditions that are very hard to diagnose and fix).

提交回复
热议问题