并发选择在同一个共享通道上

huangapple go评论78阅读模式
英文:

Concurrent selects over same shared channel

问题

我在思考如果多个goroutine在一组通道上执行select,其中一个或多个通道在它们之间共享,而当它们都在等待时,共享通道变得可用,会发生什么。

运行时会处理这种情况,并且只允许一个goroutine访问通道并进行读取/写入操作。

英文:

I was thinking what would happen if multiple goroutines are executing select over a set of channels where one/some of them are shared amongst them and while all of them are waiting, the shared channel becomes available.

Will runtime handle this case and allow only one goroutine to access the channel and do the read/write?

答案1

得分: 1

上面的评论都回答了这个问题。你也可以编写一些代码自己试试看。以下是一个示例:https://play.golang.org/p/4ZQLwO9wvw

英文:

The comments above all answer it. Also you can write some code and see for yourself. Something on these lines https://play.golang.org/p/4ZQLwO9wvw

huangapple
  • 本文由 发表于 2017年9月7日 23:14:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/46099877.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定