can you explain why whis ? 在 2016年11月4日星期五 UTC+8下午1:16:39,Ian Lance Taylor写道: > > On Thu, Nov 3, 2016 at 8:37 PM, 刘桂祥 <liuguix...@gmail.com <javascript:>> > wrote: > > // example.go > > > > package main > > > > var gMap = make(map[int]int) > > > > func w() { > > temp := make(map[int]int) > > temp[1] = 100 > > temp[2] = 200 > > gMap = temp // Does the compiler or cpu will reorder temp[1]=100, > > temp[2]=200, gMap=temp ?? > > } > > > > func r() { > > local := gMap > > println(local[1], local[2]) > > } > > > > func main() { > > > > go w() > > go r() > > > > // ... > > } > > > > I have one goroutine to read the map and one goroutine to rewrite the > global > > map variable does this safe ?? > > No. Use a lock. > > Ian >
-- 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.