https://github.com/golang/go/wiki/CommonMistakes
CommonMistakes
https://golang.org/doc/faq#closures_and_goroutines
Why is there no goroutine ID? ¶
Goroutines do not have names; they are just anonymous workers. They expose no unique identifier, name, or data structure to the programmer. Some people are surprised by this, expecting the go
statement to return some item that can be used to access and control the goroutine later.
The fundamental reason goroutines are anonymous is so that the full Go language is available when programming concurrent code. By contrast, the usage patterns that develop when threads and goroutines are named can restrict what a library using them can do.
Here is an illustration of the difficulties. Once one names a goroutine and constructs a model around it, it becomes special, and one is tempted to associate all computation with that goroutine, ignoring the possibility of using multiple, possibly shared goroutines for the processing. If the net/http
package associated per-request state with a goroutine, clients would be unable to use more goroutines when serving a request.
Moreover, experience with libraries such as those for graphics systems that require all processing to occur on the "main thread" has shown how awkward and limiting the approach can be when deployed in a concurrent language. The very existence of a special thread or goroutine forces the programmer to distort the program to avoid crashes and other problems caused by inadvertently operating on the wrong thread.
For those cases where a particular goroutine is truly special, the language provides features such as channels that can be used in flexible ways to interact with it.
https://github.com/golang/go/wiki/CommonMistakes的更多相关文章
- 下载安装go插件包报错fatal: unable to access 'https://github.com/golang/tools.git/': OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 10054
使用git命令来给vscode安装go插件的时候报错,如下: $ git clone https://github.com/golang/tools.git tools Cloning into 't ...
- https://github.com/golang/crypto/blob/master/bcrypt/bcrypt.go
https://github.com/golang/crypto/blob/master/bcrypt/bcrypt.go
- Golang优秀开源项目汇总, 10大流行Go语言开源项目, golang 开源项目全集(golang/go/wiki/Projects), GitHub上优秀的Go开源项目
Golang优秀开源项目汇总(持续更新...)我把这个汇总放在github上了, 后面更新也会在github上更新. https://github.com/hackstoic/golang-open- ...
- https://github.com/arut/nginx-rtmp-module.git
https://github.com/arut/nginx-rtmp-module.git NGINX-based Media Streaming Server nginx-rtmp-module P ...
- Golang通过git clone beego框架报错 error: while accessing https://github.com/astaxie/beego/info/refs fatal: HTTP request failed package github.com/astaxie/beego: exit status 128
在Centos6.4尝试搭建beego框架,使用git命令clone时报错 # cd .; git clone https://github.com/astaxie/beego /www/projec ...
- https://github.com/chenghuige/tensorflow-exp/blob/master/examples/sparse-tensor-classification/
https://github.com/chenghuige/tensorflow-exp/blob/master/examples/sparse-tensor-classification/ ...
- https原理以及golang基本实现
关于https 背景知识 密码学的一些基本知识 大致上分为两类,基于key的加密算法与不基于key的加密算法.现在的算法基本都是基于key的,key就以一串随机数数,更换了key之后,算法还可以继续使 ...
- 转载请注明出处: https://github.com/qiu-deqing/FE-interview
转载请注明出处: https://github.com/qiu-deqing/FE-interview Table of Contents generated with DocToc FE-inter ...
- fatal: could not read Username for 'https://github.com': No such file or directo
Git push origin master报错 fatal: could not read Username for 'https://github.com': No such file or di ...
随机推荐
- Java“微服务”还能这么玩!
"微服务"加个引号是因为这不是传统定义的微服务架构,顶多算是"小服务"架构,因为服务实例由集群节点统一加载,非独立部署.下面以图说明一下服务调用流程. 一. ...
- 使用shell发送邮件,方便快捷
目录 前言 鉴赏代码 总结 前言 很多时候我们需要发送邮件,比如定时任务,比如邮件验证码等等. 各大编程语言都可以实现发送邮件功能,但还是太麻烦了,所以通过tcpdump抓包发现smtp发送邮件原理还 ...
- jrebel 启动失败的处理
jrebel 启动失败的处理 今天使用 jrebel 启动项目的时候,突然啥日志都没有,只有一句Disconnected from the target VM, address: '127.0.0.1 ...
- 解决在Filter中读取Request中的流后, 然后再Control中读取不到的做法
摘要: 大家知道, StringMVC中@RequestBody是读取的流的方式, 如果在之前有读取过流后, 发现就没有了. 我们来看一下核心代码: filter中主要做的事情, 就是来校验请求是否合 ...
- SM4
整体结构 T变换 SM4解密的合理性证明 秘钥扩展
- JavaScript 函数节流和函数去抖
概念 函数防抖(debounce) 当调用动作过n毫秒后,才会执行该动作,若在这n毫秒内又调用此动作则将重新计算执行时间 函数节流(throttle) 预先设定一个执行周期,当调用动作的时刻大于等于执 ...
- Docker安装系列教程
首先准备一台Centos7版本的虚拟机,它支持docker容器技术.本案例使用centos7虚拟机安装docker容器. 一.安装 1.启动虚拟机,配置虚拟机能够访问互联网 2. 安装支持软件包,提供 ...
- pydub "Couldn't find ffmpeg or avconv - defaulting to ffmpeg" 问题解决
我通过 命令行安装了pydub库,运行报了如下错误 RuntimeWarning: Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but ...
- GitHub上的开源复刻:暗黑破坏神2
现在的00后少年可能已经不太了解<暗黑破坏神2>这款由暴雪打造的经典游戏. 该游戏上市的时候,国内个人家用电脑还没有那么普及,网络游戏也没有那么风靡,现在的孩子可能无法想象,那时候网吧里的 ...
- ES6模板字符串及字符串的扩展方法
一.ES6模板字符串 传统定义字符串的方式是: const str='hello es2015,this is a string' ES6新增了一种定义字符串的方式用反引号进行标识 const str ...