【发布时间】:2016-06-27 10:36:56
【问题描述】:
type driver struct {
variables map[string]string
}
var Drivers []driver
func main() {
driver := driver{
variables: make(map[string]string),
}
Drivers = append(Drivers, driver)
driver.variables = make(map[string]string) // Commenting this line makes it work, too
done := make(chan bool)
go driver.populate(done)
<-done
fmt.Print(Drivers[0].variables)
}
func (this *driver) populate(done chan bool) {
time.Sleep(500 * time.Millisecond)
this.variables["a"] = "b"
done <- true
}
我预计:
map[a:b]
实际结果:
map[]
【问题讨论】:
标签: go struct reference slice goroutine