package main
import (
"fmt"
"math/rand"
"time"
)
type Test struct {
Data *Test2
}
type Test2 struct {
Id int
}
func main() {
rand.Seed(time.Now().Unix())
o := Test{
Data: &Test2{Id: 100},
}
go func() {
for {
time.Sleep(time.Second)
o.Data = &Test2{Id: rand.Intn(10000)}
}
}()
for {
time.Sleep(time.Second)
if o.Data != nil {
fmt.Println(o.Data.Id)
}
}
}
//以上代码并发安全吗,求解释
有疑问加站长微信联系(非本文作者)