Last active
April 19, 2020 14:10
-
-
Save minhphong306/4eb680e5d4271a301870acd7e2f5f265 to your computer and use it in GitHub Desktop.
race_condition.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"sync" | |
) | |
var x int64 = 0 | |
func addOne(wg *sync.WaitGroup) { | |
x = x + 1 | |
wg.Done() | |
} | |
func main() { | |
var w sync.WaitGroup | |
for i := 0; i < 1000; i++ { | |
w.Add(1) | |
go addOne(&w) | |
} | |
w.Wait() | |
fmt.Println("Giá trị của x là: ", x) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment