大家好,欢迎来到IT知识分享网。
多线程在并发和并行环境中的不同作用
PS:在多核时代来临后,开发多线程程序的能力更是每个程序员都该具备的.
并发和并行的区别就是一个处理器同时处理多个任务和多个处理器或者是多核的处理器同时处理多个不同的任务。
前者是逻辑上的同时发生(simultaneous),而后者是物理上的同时发生.
来个比喻:并发和并行的区别就是一个人同时吃三个馒头和三个人同时吃三个馒头。
Concurrency and parallelism are two related to concepts which deals with executing tasks “simultaneously”. From Sun’s Multithreaded Programming Guide :
Concurrency: A condition that exists when at least two threads are making progress. A more generalized form of parallelism that can include time-slicing as a form of virtual parallelism.
Parallelism: A condition that arises when at least two threads are executing simultaneously.
These two definitions are too formal to be understood easily. On the Internet, there is one image which demonstrates the difference between these two in an easy way:
Much easier to understand,right? For concurrency, tasks can start, run and complete in overlapping the time periods, but they may not run at the same instant, when one task in a queue is running, another task in the other queue will wait. While for parallelism, two tasks can run at the same instant. Concurrency has states which means they know status of other tasks execution, while parallelism is stateless.
With concurrency, we want to improve the responsiveness of the application, with parallelism, we want to improve the utilization efficiency of processors, as the computing speed of a single CPU is driving to its limit, so we try to integrate more processors on a single CPU to distribute tasks among different processors.
免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://haidsoft.com/129305.html