golang 并发 vs 并行 (Concurrency Is Not Parallelism)
2022-03-13 15:10 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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 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写在同一个文件里