Any race is a bug. When there is a race, the compiler is free to do whatever it wants.
What do you want to do? Do you want to println before or after cancelContext? In your example, println could even be executed during cancelContext! Your example is not enough, such program : https://play.golang.org/p/KJsYwu-ivjb would fix your problem, but I don't think that's what you asked for :) Le vendredi 16 mars 2018 03:11:49 UTC+1, Anmol Sethi a écrit : > > https://play.golang.org/p/82Um1jSntBo > > Please run with the race detector to see the race. > > This race condition arises because private variables are read via > reflection by the fmt package. Is there any elegant way to avoid such a > race? > > -- > Best, > Anmol > > -- 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.