[go-nuts] Multiple multicast listeners in different goroutines

2023-11-14 Thread 王富民awaw
Hi Gophers and network experts, I am calling `net.ListenMulticastUDP` in each http handler, attempting to act as a fan-out proxy to multiple browsers, since browsers cannot connect to UDP directly. However, at any given time, only one single UDP listener is able to read data from the socket. O

Re: [go-nuts] Re: Is "When in doubt, use a pointer receiver" misleading advice?

2023-11-14 Thread Robert Engels
Switching to pointer receivers everywhere actually makes this worse. Any access is potentially a data race. It stills seems like this is a compiler issue. There needs to be a way to synchronize the pointer to value copy in conjunction with other synchronization. The only way to do this would be to

Re: [go-nuts] Re: Is "When in doubt, use a pointer receiver" misleading advice?

2023-11-14 Thread Mike Schinkel
On Tuesday, November 14, 2023 at 6:16:58 PM UTC-5 burak serdar wrote: It is a data race because calling rpc.version() makes a copy of rpc, which causes reading the field rpc.result concurrently while it is being written by the goroutine. Thank you for explaining. I think I am starting to see it

Re: [go-nuts] Re: Is "When in doubt, use a pointer receiver" misleading advice?

2023-11-14 Thread burak serdar
I do not agree that this is because how the compiler works. A value receiver is equivalent to pass-by-value argument, that is: rcp.version() is equivalent to: RPC.version(rpc) thus, creating the copy of the rpc variable. So, the compiler may choose to avoid the race by not copying it, or by inl

Re: [go-nuts] Re: Is "When in doubt, use a pointer receiver" misleading advice?

2023-11-14 Thread burak serdar
It is a data race because calling rpc.version() makes a copy of rpc, which causes reading the field rpc.result concurrently while it is being written by the goroutine. On Tue, Nov 14, 2023 at 3:59 PM Mike Schinkel wrote: > > On Monday, November 13, 2023 at 11:28:00 PM UTC-5 Dan Kortschak wrote: >

Re: [go-nuts] Re: Is "When in doubt, use a pointer receiver" misleading advice?

2023-11-14 Thread Mike Schinkel
On Monday, November 13, 2023 at 11:28:00 PM UTC-5 Dan Kortschak wrote: https://dave.cheney.net/2015/11/18/wednesday-pop-quiz-spot-the-race Thanks for that link. However, after studying it for well more than an hour I cannot figure out why it is a data race, and unfortunately Dave Cheney didn