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的更多相关文章

  1. 下载安装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 ...

  2. https://github.com/golang/crypto/blob/master/bcrypt/bcrypt.go

    https://github.com/golang/crypto/blob/master/bcrypt/bcrypt.go

  3. Golang优秀开源项目汇总, 10大流行Go语言开源项目, golang 开源项目全集(golang/go/wiki/Projects), GitHub上优秀的Go开源项目

    Golang优秀开源项目汇总(持续更新...)我把这个汇总放在github上了, 后面更新也会在github上更新. https://github.com/hackstoic/golang-open- ...

  4. 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 ...

  5. 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 ...

  6. https://github.com/chenghuige/tensorflow-exp/blob/master/examples/sparse-tensor-classification/

        https://github.com/chenghuige/tensorflow-exp/blob/master/examples/sparse-tensor-classification/ ...

  7. https原理以及golang基本实现

    关于https 背景知识 密码学的一些基本知识 大致上分为两类,基于key的加密算法与不基于key的加密算法.现在的算法基本都是基于key的,key就以一串随机数数,更换了key之后,算法还可以继续使 ...

  8. 转载请注明出处: https://github.com/qiu-deqing/FE-interview

    转载请注明出处: https://github.com/qiu-deqing/FE-interview Table of Contents generated with DocToc FE-inter ...

  9. 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 ...

随机推荐

  1. 让API并行调用变得如丝般顺滑的绝招

    当数据量较大的时候,都会通过分库分表来拆分,分担读写的压力.分库分表后比较麻烦的就是查询的问题,如果不是直接根据分片键去查询的话,需要对多个表进行查询. 在一些复杂的业务场景下,比如订单搜索,除了订单 ...

  2. PIX

    [开启]后,如图: [新建]:如图中设定: Program: 你要准备监测的应用程序路径 [点击]:Start Experiment 如图,会出现一个新窗口(你运行的应用程序窗口) [点击F12](确 ...

  3. easyui中加载table列表数据 第一次有数据第二次没有数据问题

    $('#allUsingProductTable').datagrid({  加载数据时,第二加载时table会发生变化会出现找不到问题.如果是弹框没有影响,弹框出现出现列表每次都会执行销毁方法. 解 ...

  4. idea中快捷键换成熟悉的celipse中快捷键

    打开idea,找到菜单栏的file,点击打开,找到settings,打开   用key做关键词搜索keymap   找到之后点击打开,右侧就会显示快捷键界面,可以点击查看每一项 4 默认为defaul ...

  5. 记一次诡异的debug

    idea debug的时候会开启一个线程之行 toString,所以我们一般不要在toString 做什么操作. 目前在读spring解析自定义标签的源. 解析过程中在XmlBeanDefinitio ...

  6. Markdown高级使用之流程图

    流程图在Markdown中的的表现形式就是代码块,代码块语言标记为mermaid.主要内容大体分为:方向.节点.节点间的连接关系,下面就围绕这三个点来整理. mermaid支持流程图.甘特图和时序图, ...

  7. java集合并发操作异常解决方法:CopyOnWriteArrayList

    一.我们知道ArrayList是线程不安全的,请编写一个不安全的案例并给出解决方案 HashSet与ArrayList一致 HashMap HashSet底层是一个HashMap,存储的值放在Hash ...

  8. pthread 读写锁

    pthread 读写锁 (Read Write Lock, rwlock) 把对共享资源的访问者分为读者和写者,读者仅仅对共享资源进行读访问,写者仅仅对共享资源进行写操作. 如果使用互斥量 mutex ...

  9. 【C++】《Effective C++》第五章

    第五章 实现 条款26:尽可能延后变量定义式的出现时间 只要定义了一个变量而其类型带有一个构造函数或析构函数,那么 当程序的控制流到达这个变量定义式时,你得承受这个构造成本. 当这个变量离开这个作用域 ...

  10. MongoDB备份(mongodump)与恢复(mongorestore)工具实践

    mongodump和mongorestore实践 1.mongodump备份工具 mongodump能够在Mongodb运行时进行备份,它的工作原理是对运行的Mongodb做查询,然后将所有查到的文档 ...