Threading vs Parallelism, how do they differ?

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

What is the difference between threading and parallelism?

Which one has advantage over the other?

9条回答
  •  Happy的楠姐
    2020-12-04 08:09

    Parallelism is a general technique of using more than one flow of instructions to complete a computation. The critical aspect of all parallel techniques is communicating between flows to collaborate a final answer.

    Threading is a specific implementation of parallelism. Each flow of instructions is given it's own stack to keep a record of local variables and function calls, and communicates with the other flows implicitly by shared memory.

    One example might be to have one thread simply queue up disk requests and pass it to a worker thread, effectively parallelizing disk and CPU. The traditional UNIX pipes method is to split these into two complete programs, say "cat" and grep in the command:

    cat /var/log/Xorg.0.log | grep "EE"
    

    Threading could conceivably reduce the communication costs of copying disk I/O from the cat process to the grep process.

提交回复
热议问题