func main() {
var number int = 0
go func() {
for {
number++
//time.Sleep(time.Nanosecond)
}
}()
fmt.Println(number)
time.Sleep(time.Second)
number的打印总是0,但是在for循环中加上time.Sleep(time.Nanosecond)语句后,value的打印就正常了。为什么?
一只名叫tom的猫
相关分类