并发和并行有什么区别?

做并发编程之前,必须首先理解什么是并发,什么是并行,什么是并发编程,什么是并行编程。

并发(concurrency)和并行(parallellism)是:

  1. 解释一:并行是指两个或者多个事件在同一时刻发生;而并发是指两个或多个事件在同一时间间隔发生。
  2. 解释二:并行是在不同实体上的多个事件,并发是在同一实体上的多个事件
  3. 解释三:在一台处理器上“同时”处理多个任务,在多台处理器上同时处理多个任务。如hadoop分布式集群

所以并发编程的目标是充分的利用处理器的每一个核,以达到最高的处理性能。

各位是如何理解并行和并发的呢?

原创文章,转载请注明: 转载自并发编程网 – ifeve.com本文链接地址: 并发和并行有什么区别?


FavoriteLoading添加本文到我的收藏
    • 泡泡
    • 2013/01/08 10:23下午

    并行: 就是等于号

    并发: 就是大于号

      • 泡泡
      • 2013/01/08 10:34下午

      通俗点说 并发就是不同线程同时干一件事情
      并行就是不同线程同时干不同的事情

    • 天涯
    • 2013/03/08 9:31上午

    Quote“并行(concurrency)和并发(parallellism)”
    这是在误导!!
    请好好查查字典再发帖子,你刚好把两个词的英文写反了!!

    • 匿名
    • 2013/04/17 10:10上午

    《并发的艺术》中大概是这样写的,系统中有多个任务同时存在可称之为“并发”,系统内有多个任务同时执行可称之为“并行”;并发是并行的子集。比如在单核CPU系统上,只可能存在并发而不可能存在并行。

      • 低调求生存
      • 2013/06/07 11:11下午

      You can get concurrency on a single core processor using preemptive time-shared threads. But what you cannot achieve on a single core processor is parallelism.

    • 低调求生存
    • 2013/06/07 11:08下午

    感觉你的描述还是体会不出什么具体的区别,下面是Stackoverflow上的摘要:
    It’s well understood that concurrency is decomposition of a complex problem into smaller components. If you cannot correctly divide something into smaller parts, it’s hard to solve it using concurrency. but it is wrong b/c those smaller components may depend on each other in a sequential manner to complete, so even if you divide into small components, it does not mean you achieve concurrency / parallelism.
    In all my classes of parallel and distributed algorithms (both in BS and MS) we never talked about “concurrency we obtained and now let’s see how to obtain parallelism”. If you use the word concurrency to describe and algorithm then you imply parallelism and vice versa.
    When you have the abstract form of an algorithm in mind, you then have to choose if you will implement it with Message Passing or Shared Memory or maybe Hybrid. You will also have to consider the type of memory access (NUMA, UMA, etc) and the Topology used (Hypercube, Torus, Ring, Mesh, Tree, etc)
    This seems a lot of work to someone who just wants something, maybe even simple, done in a parallel way (e.g. parallel for).
    And it is a lot of work especially if you change the topology (so you can have all of its advantages).
    So you write the parallel code (be it simple or complex) and the VM or compiler will choose what seems to be the best way to go, even running it in a sequential way! (an example would be Task Parallel Library for .net).And it should mention that I am talking about concurrency in a program / algorithm and not between independent programs that run in a system.

    From an implementation point of view, if you say “parallelism” you usually intend a program that runs on the local computer or a cluster (Shared Memory communication), and “distributed” when you run the program on a grid (Message Passing communication).

    so this also mean concurrency as the abstract principle and parallel as the way it is implemented [Shared Memory, Message Passing, Hybrid between both; Type of memory acces (numa, uma, etc)].

    BTW:You can get concurrency on a single core processor using preemptive time-shared threads. But what you cannot achieve on a single core processor is parallelism.

    Reference:
    Concurrency is not Parallelism(it’s better): http://concur.rspace.googlecode.com/hg/talk/concur.html

    • ada
    • 2013/07/24 9:28上午

    并发是逻辑上的同时发生,并行更多是侧重于物理上的同时发生。并发往往是指程序代码的结构支持并发,并发的程序在多cpu上运行起来才有可能达到并行,并行往往是描述运行时的状态。

    • 匿名
    • 2013/10/29 11:08下午

    所以并发编程的目标是充分的利用处理器的每一个核,以达到最高的处理性能。

    那并行编程的目标是什么??

    • zhengJackson
    • 2013/11/01 11:18上午

    天涯 :
    Quote“并行(concurrency)和并发(parallellism)”
    这是在误导!!
    请好好查查字典再发帖子,你刚好把两个词的英文写反了!!

    到底是哪个?文章是还没来得及修改?

    • ligang7121087
    • 2016/04/04 11:49下午

    3.解释三:在一台处理器上“同时”处理多个任务,在多台处理器上同时处理多个任务。如hadoop分布式集群
    并发:在一台处理器上”同时”处理多个任务
    并行:在多台处理器上同时处理多个任务,比如说hadoop分布式集群

    • Simba_cheng
    • 2016/10/18 11:03下午

    并行 : 双十一 , 零时零分零秒,三十万用户同时登录淘宝网

    并发 : 双十一 , 零时零分零秒 至 两点零分零秒 共有一百万用户登录淘宝网.

  1. 暂无 Trackback

您必须 登陆 后才能发表评论

return top