Is this applied when the channel is nil? Does select statement first lock the channel then check if it's nil?
On Wednesday, January 24, 2018 at 6:07:50 PM UTC+3:30, Ian Lance Taylor wrote: > > On Tue, Jan 23, 2018 at 10:13 PM, dc0d <kaveh.sh...@gmail.com > <javascript:>> wrote: > > > > The third option was the expected one. Locking aside (as the thought > line > > behind the original question), the time spent on preparing/calculating a > > result value to be sent to a channel, is not directly relevant to the > case > > for nil channels - which were expected to get ignored. I do not > understand > > the internals of select statement and did not know it locks the channel. > > Regardless of internal details, conceptually it has to lock the > channel. The select statement has to atomically 1) decide that the > channel has room for a new value; 2) send the new value to the > channel. There could be many goroutines sending to the channel > simultaneously. If the select statement picks the channel first and > then computes the value to send, then it has to ensure that no other > goroutine can send to the channel while computing the value, as > otherwise once it has the value it might not be able to send it. > > Ian > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.