并发选择同一共享通道

并发选择同一共享通道

问题描述:

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?

我在想,如果多个goroutine在一组通道上执行 select code>,会发生什么 在其中一个/其中一个被共享的状态下,当它们都在等待时,共享的通道变为可用。 p>

运行时将处理这种情况,并且仅允许一个goroutine访问该通道,并且 可以读/写吗? p> div>

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