• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

GoConcurrency

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

Go Concurrency

1、A goroutine is a lightweight thread managed by the Go runtime.

  

2、Channels are a typed conduit through which you can send and receive values with the channel operator, <-.

  

3、Like maps and slices, channels must be created before use:

  

  By default, sends and receives block until the other side is ready. This allows goroutines to synchronize without explicit locks or condition variables.

  

4、Channel会缓存。

  

5、A sender can close a channel to indicate that no more values will be sent. Receivers can test whether a channel has been closed by assigning a second parameter to the receive expression: after

  

  ok is false if there are no more values to receive and the channel is closed.

  The loop for i := range c receives values from the channel repeatedly until it is closed.

  Note: Only the sender should close a channel, never the receiver. Sending on a closed channel will cause a panic.

  Another note: Channels aren't like files; you don't usually need to close them. Closing is only necessary when the receiver must be told there are no more values coming, such as to terminate a range loop.

  

6、The select statement lets a goroutine wait on multiple communication operations.

  A select blocks until one of its cases can run, then it executes that case. It chooses one at random if multiple are ready.

  

  

7、The default case in a select is run if no other case is ready.

  Use a default case to try a send or receive without blocking:

  

参考:https://tour.golang.org/concurrency/1


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap