英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论