![](/img/trans.png)
[英]What's the difference between Firebase AngularFireAuth and Auth?
[英]What's the difference between Data Race and Condition in Go?
嗨,我是 go 的新手,我目前仍在學習它,關於數據競爭和競爭條件之間的區別有一個問題,我對它之間的區別有點困惑,有人可以告訴我兩者之間的真正區別是什么那些條件和樣本答案? 提前致謝
數據競爭是變量與其他變量的讀寫同時寫入的地方。 這是一個數據競爭示例:
x := 1
go func() { x = 2 }() // The write to x on this line executes ...
fmt.Println(x) // concurrently with the read on this line
該程序可以打印 1、2 或以某種未指定的方式失敗。
競爭條件是同時執行的代碼由於時間而產生不同的結果。 這是一個競爭條件示例:
ch := make(chan int, 1)
go func() { ch <- 1 }()
go func() { ch <- 2 }()
fmt.Println(<-ch)
goroutine 競相向通道發送一個值。 該程序可以打印 1 或 2。
數據競爭是一種競爭條件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.