On Wednesday, 23 February 2022 at 13:51:23 UTC yan.z...@gmail.com wrote: > Hi Brian! > Your code with a map of channels is quite impressive! How can I test if > the code has no races in case I have many go files inside a folder? > `go build -race`? >
I believe so (or "go build -race ." with the dot) Now, I was thinking to myself that the race detector isn't necessary here. Since there are no global variables and no pointers being passed over channels, it's provably race-free. But there is one wrinkle, which is that interface values are implicitly boxed pointers. Roughly speaking, the box contains a <type, pointer> pair. Now, I believe that interface values are copied before being boxed/unboxed, and I believe that it's not possible to use interfaces for aliasing, in a way that mutating one copy of the interface value affects another one. But I don't know where exactly it says so in the language spec. At least, I've not found a way to make this aliasing happen: https://go.dev/play/p/GAXybxUxfqJ If that's guaranteed by the language, then the code is good as it stands, but it remains a subtle point. The only reason I used an interface in the first place was as a way of carrying different structs over the same channel, effectively using it as a tagged union. -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/12033d20-19af-4847-9dff-ea106deef494n%40googlegroups.com.