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.

最新文章

  1. Switch重构处理
  2. oracle 监听启动、停止、查看命令
  3. BZOJ 1047: [HAOI2007]理想的正方形
  4. 第51讲:Scala中链式调用风格的实现代码实战及其在Spark编程中的广泛运用
  5. 非阻塞同步算法与CAS(Compare and Swap)无锁算法
  6. case while for
  7. (实用篇)PHP中单引号与双引号的区别分析
  8. hdu 5682 zxa and leaf
  9. Java基础详解 (一)Java的类成员访问权限修饰词(以及类访问权限)
  10. 【风马一族_xml】xmlp之dtd1
  11. NOIP2001 一元三次方程求解
  12. linux环境下编码的问题
  13. jquery实现仿select列表的即时搜索及拼音搜索
  14. python入门(12)dict
  15. mybatis源码解读(二)——构建Configuration对象
  16. java linux sdk1.8
  17. echart.js在vue中使用
  18. NC nc开发工具java虚拟机参数
  19. 基于Spring Cloud的微服务入门教程
  20. Filter过滤器介绍

热门文章

  1. ava基础MySQL存储过程 Java基础 JDBC连接MySQL数据库
  2. ESP8266系列图片外观 Wi-Fi模块一共有01~14十多款模块
  3. Spring Boot的自动配置
  4. OpenSUSE 使用基础
  5. linux 怎么样复制文件夹内所有文件到另一个文件夹?
  6. 关于Webservice接口对接相关总结
  7. 避坑 | Java8使用并行流(ParallelStream)注意事项
  8. 用python+sklearn(机器学习)实现天气预报 准备
  9. NOIP初赛篇——08计算机安全知识
  10. .netcore 急速接入第三方登录,不看后悔