a string
var done bool
func setup() {
a = "hello, world"
done = true
}
func main() {
go setup()
for !done {
}
print(a)
}
為啥我的輸出是 hello,world。。。
Go的內(nèi)存模型介紹 如何保證在一個goroutine中看到在另一個goroutine修改的變量的值,這篇文章進(jìn)行了詳細(xì)說明。 建議 如果程序中修改數(shù)據(jù)時有其他goroutine同時讀取,那...