代码改变世界

golang 并发 vs 并行 (Concurrency Is Not Parallelism)

  youxin  阅读(76)  评论(0编辑  收藏  举报

Rob pike发表过一个有名的演讲《Concurrency is not parallelism》(https://blog.golang.org/concurrency-is-not-parallelism),

演讲胶片在talks.golang.org中可以找到(https://talks.golang.org/2012/waza.slide#1),

演讲视频地址 :https://vimeo.com/49718712

 

The modern world is parallel

Multicore.

Networks.

Clouds of CPUs.

Loads of users.

Our technology should help.
That's where concurrency comes in.

 

Go supports concurrency

Go provides:

  • concurrent execution (goroutines)
  • synchronization and messaging (channels)
  • multi-way concurrent control (select)

Concurrency is cool! Yay parallelism!!

NO! A fallacy.

When Go was announced, many were confused by the distinction.

"I ran the prime sieve with 4 processors and it got slower!"

 

fallacy:

n. 谬论,谬见;推理谬误;谬误性

Concurrency

Programming as the composition of independently executing processes.

(Processes in the general sense, not Linux processes. Famously hard to define.)

 

Parallelism

Programming as the simultaneous execution of (possibly related) computations.

 

Concurrency vs. parallelism

Concurrency is about dealing with lots of things at once.

Parallelism is about doing lots of things at once.

Not the same, but related.

Concurrency is about structure, parallelism is about execution.

Concurrency provides a way to structure a solution to solve a problem that may (but not necessarily) be parallelizable.

 

An analogy

Concurrent: Mouse, keyboard, display, and disk drivers.

Parallel: Vector dot product.

analogy:

n. 类比,比拟;用类比方法,进行比照;同功

 

 

Concurrency plus communication

Concurrency is a way to structure a program by breaking it into pieces that can be executed independently.

Communication is the means to coordinate the independent executions.

This is the Go model and (like Erlang and others) it's based on CSP:

C. A. R. Hoare: Communicating Sequential Processes (CACM 1978)

 

并发模型中的csp模型:https://www.zhihu.com/question/26192499

 

参考;https://blog.csdn.net/abccheng/article/details/50913795

 

相关博文:
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
历史上的今天:
2014-03-13 《how to design programs》14章 再论自引用数据
2013-03-13 设计模式之解释器模式
2013-03-13 javascript创建css样式
2013-03-13 js和css写在同一个文件里
点击右上角即可分享
微信分享提示