Threading vs Parallelism, how do they differ?
What is the difference between threading and parallelism?
Which one has advantage over the other?
Daniel Moth (a former coworker of mine)- Threading/Concurrency vs Parallelism article explains it all.
Quoted:
To take advantage of multiple cores from our software, ultimately threads have to be used. Because of this fact, some developers fall in the trap of equating multithreading to parallelism. That is not accurate...You can have multithreading on a single core machine, but you can only have parallelism on a multi core machine
The quick test: If on a single core machine you are using threads and it makes perfect sense for your scenario, then you are not "doing parallelism", you are just doing multithreading.
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.
线程是一种技术,并行是一种可以使用线程来实现的范例(但在多处理器上使用单线程就可以轻松完成)
链接地址: http://www.djcxy.com/p/79308.html上一篇: 你如何利用多核?
下一篇: 线程vs并行,它们有什么不同?