Multiple receivers on a single channel. Who gets the data?

前端 未结 3 462
不思量自难忘°
不思量自难忘° 2021-01-04 03:54

Unbuffered channels block receivers until data is available on the channel. It\'s not clear to me how this blocking behaves with multiple receivers on the same channel (say

3条回答
  •  花落未央
    2021-01-04 04:01

    If the program is allowing multiple goroutines to receive on a single channel then the sender is broadcasting. Each receiver should be equally able to process the data. So it does not matter what mechanism the go runtime uses to decide which of the many goroutine receivers will run Cf. https://github.com/golang/go/issues/247. But only ONE will run for each sent item if the channel is unbuffered.

提交回复
热议问题