On Thursday, 3 November 2016 23:54:46 UTC-4, 刘桂祥 wrote: > > sorry could you provide a complete example ? > > I try this but not find question > package main > > > import "time" > > > type T struct{ x int } > > > var global *T > > > func f() { > p := new(T) > p.x = 1 > global = p // "publish" the new T (racy!) > } > > > func g() { > p := global > if p != nil { > // println(p.x) // may print "0" due to data race > if p.x == 0 { > panic("ca") > } > } > } > func main() { > for i := 0; i < 10000; i++ { > go func() { > for j := 0; j < 1000; j++ { > f() > } > }() > go func() { > for j := 0; j < 1000; j++ { > g() > } > }() > } > time.Sleep(100 * time.Second) > } >
I think you are saying you failed to observe a data race during execution of this program. It is not safe to conclude that a program does not have a data race just because you didn't notice it. The behavior of a program containing a data race depends on many things, including the set of optimizations done by a compiler, and the architecture and microarchitecture of the processor. If you build this program with the -race flag, the dynamic race detector will almost certainly detect and report a problem. -- 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.