### The Go Memory Model
文章结尾有这么一段代码,理解的不是很透彻,谁给讲解一下,谢谢!
There are subtler variants on this theme, such as this program.
```
type T struct {
msg string
}
var g *T
func setup() {
t := new(T)
t.msg = "hello, world"
g = t
}
func main() {
go setup()
for g == nil {
}
print(g.msg)
}
```
Even if main observes g != nil and exits its loop, there is no guarantee that it will observe the initialized value for g.msg.
In all these examples, the solution is the same: use explicit synchronization.
等同于Sleep
```
package main
import (
"time"
)
type T struct {
msg string
}
var g *T
func setup() {
t := new(T)
t.msg = "hello, world"
g = t
}
func main() {
go setup()
time.Sleep(time.Second * 5)
print(g.msg)
}
```
#7