How to understand this behavior of goroutine?
问题 package main import ( "fmt" "time" ) type field struct { name string } func (p *field) print() { fmt.Println(p.name) } func main() { data := []field{ {"one"},{"two"},{"three"} } for _,v := range data { go v.print() } <-time.After(1 * time.Second) } why does this code print 3 "three" instead of "one" "two" "three" in any order? 回答1: There is a data race. The code implicitly takes address of variable v when evaluating arguments to the goroutine function. Note that the call v.print() is