Golang channels select statement

半城伤御伤魂 提交于 2019-12-08 19:53:44

问题


Just experimenting with go recently. I was wondering what will happen if you have a select statement waiting for communication on a few channels and if a message comes AT THE SAME time on two or more channels. How will the select determine which channel to accept if all the messages come at the same time?

Thanks!


回答1:


From the spec:

If multiple cases can proceed, a uniform pseudo-random choice is made to decide which single communication will execute.

So the choice is non-deterministic.



来源:https://stackoverflow.com/questions/19865194/golang-channels-select-statement

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!