On Mon, Jun 27, 2016 at 4:38 AM, 苏沛 <sillyo...@gmail.com> wrote: > So data race may occur in len(someChan) ? Channel len is volatile. > > func reflect_chanlen(c *hchan) int { > if c == nil { > return 0 > } > return int(c.qcount) > }
The language spec specifically permits calls to len(channel) to occur concurrently with channel sends and receives. If the implementation fails to support that, that would be a bug. Of course, it follows that any real use of len(channel) other than, say, simply printing it out, is subject to race conditions. Ian > 2016-06-27 11:58 GMT+08:00 Jan Mercl <0xj...@gmail.com>: >> >> On Mon, Jun 27, 2016 at 5:44 AM 苏沛 <sillyo...@gmail.com> wrote: >> >> Data race occurs when there are concurrent accesses to the same memory and >> at least one of them is a write. Channel capacity is never written to after >> a chan is created. >> -- >> >> -j > > > > > -- > 苏沛 > > -- > 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. -- 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.