Unlike C, Go has no `volatile` keyword. Therefore, the compiler is allowed to cache a value that is never updated in the scope that it sees, and there's no way for us to tell it not to do that. Issues like this aren't really data races, but they are caught by the race detector.
On Wednesday, June 7, 2017 at 8:47:02 AM UTC-4 Fuxin Hao wrote: > "there is no guarantee that the write to done will ever > be observed by main", i am wondering why the write to done will ever > be observed by main in detail? > > > On Thursday, February 25, 2016 at 8:07:29 AM UTC+8, Nigel Tao wrote: >> >> On Tue, Feb 23, 2016 at 7:46 AM, Damian Gryski <dgr...@gmail.com> wrote: >> > On Monday, February 22, 2016 at 8:29:59 PM UTC+1, mikew...@gmail.com >> wrote: >> >> I've been trying to find a way to ignore errors from the golang race >> >> detector. In particular I have a stats loop that does stale reads from >> for a >> >> variable that is updated constantly. In this case I do not care if the >> value >> >> of the read is stale and I do not want to use atomic operations or >> locking >> >> to remove this race condition for performance reasons. Does anyone >> know if >> >> there is a way to add something to the lines of code that read this >> value to >> >> tell the race detector to ignore errors coming from a specific line of >> code? >> > >> > You might be interested in >> > >> https://software.intel.com/en-us/blogs/2013/01/06/benign-data-races-what-could-possibly-go-wrong >> >> >> See also the "an aggressive compiler might delete the entire go >> statement" and "there is no guarantee that the write to done will ever >> be observed by main" examples at https://golang.org/ref/mem >> > -- 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/72af9ce3-ae04-4d58-a275-6a6b89aca1f8n%40googlegroups.com.